Created
December 3, 2018 12:25
-
-
Save Fhernd/79dcb402afe079c89dc117a425412e1a to your computer and use it in GitHub Desktop.
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
_formatos = { | |
'amd': '{d.aghnio}-{d.mes}-{d.dia}', | |
'mda': '{d.mes}/{d.dia}/{d.aghnio}', | |
'dma': '{d.dia}/{d.mes}/{d.aghnio}' | |
} | |
class Fecha: | |
def __init__(self, agnhio, mes, dia): | |
self.aghnio = agnhio | |
self.mes = mes | |
self.dia = dia | |
def __format__(self, codigo_formato): | |
if codigo_formato == '': | |
codigo_formato = 'amd' | |
formato = _formatos[codigo_formato] | |
return formato.format(d=self) | |
fecha = Fecha(2018, 11, 30) | |
print(format(fecha)) | |
print(format(fecha, 'mda')) | |
print('La fecha es {:amd}'.format(fecha)) | |
print('La fecha es {:mda}'.format(fecha)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment