Fhernd icon

contructores_extra.py

Fhernd | PRO | 01/08/19 06:02:26 PM UTC | 0 ⭐ | 2038 👁️ | Never ⏰ | []
Python |

590 B

|

None

|

0 👍

/

0 👎

import time
 
class Fecha:
    # Constructor primario:
    def __init__(self, aghnio, mes, dia):
        self.aghnio = aghnio
        self.mes = mes
        self.dia = dia
 
    # Constructor extra:
    @classmethod
    def fecha_actual(cls):
        fecha_local = time.localtime()
 
        return cls(fecha_local.tm_year, fecha_local.tm_mon, fecha_local.tm_mday)
 
    def __str__(self):
        return '{}-{}-{}'.format(self.aghnio, self.mes, self.dia)
 
 
if __name__ == '__main__':
    fecha1 = Fecha(2019, 1, 8)
    fecha2 = Fecha.fecha_actual()
 
    print(fecha1)
    print(fecha2)

Comments

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

    0 B

    |

    👍

    /

    👎