Fhernd icon

instanciar_sin_init.py

Fhernd | PRO | 01/14/19 12:40:00 PM UTC | 0 ⭐ | 1927 👁️ | Never ⏰ | []
Python |

480 B

|

None

|

0 👍

/

0 👎

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)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎