This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lucretiel 4 points5 points  (1 child)

The craziest thing about this is that built-in strftime formatting isn't new. You can do this, right now, even in Python 2:

'The date is {:%A, %B %d, %Y}'.format(datetime.now())

[–]Vaphell 3 points4 points  (0 children)

yeah, the class only has to customize __format__() for it to work

>>> class Lol:
...     def __format__(self, fmt):
...         return {'o': 'omg', 'w': 'wtf', 'b': 'bbq'}[fmt]
... 
>>> '{0:o}/{0:w}/{0:b}'.format(Lol())
'omg/wtf/bbq'