Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 8, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/e085e2168ae33b37cfe913ad87b63e34 to your computer and use it in GitHub Desktop.
Save Fhernd/e085e2168ae33b37cfe913ad87b63e34 to your computer and use it in GitHub Desktop.
Definición de un constructor extra. Python.
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