Message106258
On Thu, May 20, 2010 at 7:27 PM, Antoine Pitrou <report@bugs.python.org> wrote:
>
>> .. The OP's premise was that
>> t.timetuple()[7] was unreadable, but in the modern python, the same
>> can be written as t.timetuple().tm_yday.
>
> Could I suggest such example be added to the documentation, though?
The documentation for timetuple method [1, 2] already contains a
recipe for computing yday which is more efficient than
t.timetuple().tm_yday:
yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1
Maybe it can be improved by making it discoverable in searches for yday:
"""
... is equivalent to time.struct_time((d.year, d.month, d.day, d.hour,
d.minute, d.second, d.weekday(), yday, dst)), where yday =
d.toordinal() - date(d.year, 1, 1).toordinal() + 1 is the day number
of the year starting from 1 for January 1st.
"""
[1] http://docs.python.org/py3k/library/datetime.html#datetime.date.timetuple
[2] http://docs.python.org/py3k/library/datetime.html#datetime.datetime.timetuple |
|
Date |
User |
Action |
Args |
2010-05-21 19:58:06 | belopolsky | set | recipients:
+ belopolsky, lemburg, mark.dickinson, pitrou, mwtoews, jborgohain |
2010-05-21 19:58:04 | belopolsky | link | issue1436346 messages |
2010-05-21 19:58:03 | belopolsky | create | |
|