Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 6, 2019 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/85be0b6706e60ced5c865686f5c30bca to your computer and use it in GitHub Desktop.
Save Fhernd/85be0b6706e60ced5c865686f5c30bca to your computer and use it in GitHub Desktop.
Incialización de estructuras de datos. Python.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment