Advertisement
Fhernd

instanciar_sin_init.py

Jan 14th, 2019
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. class Fecha:
  2.     def __init__(self, aghnio, mes, dia):
  3.         self.aghnio = aghnio
  4.         self.mes = mes
  5.         self.dia = dia
  6.  
  7.     def __str__(self):
  8.         return '{}-{}-{}'.format(self.aghnio, self.mes, self.dia)
  9.  
  10. if __name__ == '__main__':
  11.     fecha = Fecha.__new__(Fecha)
  12.  
  13.     # Produce error. El atributo no ha sido definido aún:
  14.     # fecha.mes
  15.  
  16.     setattr(fecha, 'aghnio', 2019)
  17.     setattr(fecha, 'mes', 1)
  18.     setattr(fecha, 'dia', 14)
  19.  
  20.     print(fecha)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement