Created
January 8, 2019 19:10
-
-
Save Fhernd/e085e2168ae33b37cfe913ad87b63e34 to your computer and use it in GitHub Desktop.
Definición de un constructor extra. 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment