On Wed, Dec 11, 2013 at 8:37 AM, Mark Lawrence <[email protected]> wrote:
>
> print('{}:{}:{}'.format(now.hour, now.minute, now.year))
>
> Sorry I can never remember the formatting types to go between {} so look for
> them around here http://docs.python.org/3/library/string.html#formatstrings
For datetime's date, time, and datetime types, the __format__ method
passes the spec to strftime:
>>> t = datetime.datetime(2038,1,19,3,14,7)
>>> '{:%H:%M:%S}'.format(t)
'03:14:07'
If the format spec is empty, it uses __str__:
>>> format(t)
'2038-01-19 03:14:07'
But this is unrelated to timedelta, which lacks a custom __format__.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor