Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Estructura:
- _campos = []
- def __init__(self, *args):
- if len(args) != len(self._campos):
- raise TypeError('Se esperan {} argumentos'.format(len(self._campos)))
- for nombre, valor in zip(self._campos, args):
- setattr(self, nombre, valor)
- class Producto(Estructura):
- _campos = ['Nombre', 'Cantidad', 'Precio']
- class Punto(Estructura):
- _campos = ['x', 'y']
- class Circulo(Estructura):
- _campos = ['radio']
- if __name__ == '__main__':
- producto = Producto('MacBook Pro', 3, 730)
- punto = Punto(0, 5)
- circulo = Circulo(3.0)
- producto = Producto('Samsung Frontier', 13, 280, 2017)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement