Created
January 14, 2019 13:40
-
-
Save Fhernd/156efa479172b6073f6cebb9cc7b92b4 to your computer and use it in GitHub Desktop.
Instanciar un objeto sin hacer uso del método __init__. Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fecha: | |
def __init__(self, aghnio, mes, dia): | |
self.aghnio = aghnio | |
self.mes = mes | |
self.dia = dia | |
def __str__(self): | |
return '{}-{}-{}'.format(self.aghnio, self.mes, self.dia) | |
if __name__ == '__main__': | |
fecha = Fecha.__new__(Fecha) | |
# Produce error. El atributo no ha sido definido aún: | |
# fecha.mes | |
setattr(fecha, 'aghnio', 2019) | |
setattr(fecha, 'mes', 1) | |
setattr(fecha, 'dia', 14) | |
print(fecha) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment