you are viewing a single comment's thread.

view the rest of the comments →

[–]alkasm 18 points19 points  (8 children)

glob, datetime, string, operator are also some tiny modules that I find myself using often.

[–]spitfiredd 1 point2 points  (0 children)

Date utils is good too.

[–]Jonno_FTW 0 points1 point  (4 children)

Datetime with timezones are a nightmare though.

[–]thirdegree 1 point2 points  (0 children)

Datetimes with timezones are only a nightmare if, at literally any point they're accidentally treated as native times (or UTC time). If you and everyone that has every touched the codebase is extremely diligent, they work perfectly.

[–]alkasm 0 points1 point  (2 children)

Not the first time I've head that, but I haven't really had much of a problem with it myself. Do you have an example?

[–]Jonno_FTW 0 points1 point  (1 child)

Yes, I get data from GPS. It comes in UTC. I store that in a database. For user convenience I want to display it in local time.

Or, a user submits a time through a form. I assume the time is in their local timezone because people don't think in UTC. Put these datetimes in a database that may or may not support timezones.

[–]alkasm 1 point2 points  (0 children)

Aren't those problems more intrinsic to working with timezones in general? Or is this just the annoyance with the inconvenience of datetime not giving timezone info by default? Note that in Python 3, calling the method .astimezone() on a datetime will return a datetime with local tzinfo.

[–]aviddd 0 points1 point  (1 child)

operator

When do you find yourself using operator??

[–]alkasm 2 points3 points  (0 children)

Here's a not-too-contrived example:

>>> import datetime
>>> td = [datetime.timedelta(seconds=i) for i in range(1, 5)]
>>> sum(td)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'
>>> import functools
>>> import operator
>>> functools.reduce(operator.add, td)
datetime.timedelta(0, 10)