[Python-ideas] Proposal: making __str__ count in time's class

Francesco Franchina cescus92 at gmail.com
Wed Mar 8 11:01:22 EST 2017


Hello everyone,

I'm shortly writing to you about a reflection I lately made upon the
current functioning of __str__ for the time's class.

Before expressing my thought and proposal, I want to make sure we all agree
on a simple and clear fact:
the __str__ magic method is used to give a literal and human-readable
representation to the object (unlike __repr__).

Generally this is true across the python panorama. It's not true for the
time class, for example.




*>>> import time>>> a = time.localtime()>>>
a.__str__()'time.struct_time(tm_year=2017, tm_mon=3, tm_mday=8, tm_hour=16,
tm_min=6, tm_sec=16, tm_wday=2, tm_yday=67, tm_isdst=0)'*

Well, don't get me wrong: the main aim of the __str__ method has been
accomplished but, imho, not in the most pythonic way.

I just wanted to ask you: what do you think about re-writing the __str__ of
the time class so it would return something like
ISO 8601 [https://en.wikipedia.org/wiki/ISO_8601] format? Wouldn't it be
more meaningful? Especially in the JS-everywhere-era
it could be more more productive.


*TL;DR*
__str__ for dates should return a human-readable date format (eg:
https://en.wikipedia.org/wiki/ISO_8601)


I'm waiting for your opinions.
Thank you for your time and ideas!

Francesco Franchina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170308/76cda6e9/attachment.html>


More information about the Python-ideas mailing list