zerosleeps

Since 2010

datetime.utcnow() is now deprecated

Miguel Grinberg with a nice article about the deprecation of Python’s datetime.datetime utcnow() and utcfromtimestamp() functions.

I discovered the article via this post on Hacker News which has a really great discussion about the topic.

The core Python developers are stuck between a rock and a hard place on this one. If it was up to me I’d be updating these functions to return aware datetime objects. It’s obvious that utcnow() should return a UTC datetime object, right?

But it’s a good job it’s not up to me, because this standard library is almost certainly used by millions of Python scripts! How on earth do you change something like that without upsetting a lot of people? You can’t throw deprecation warnings for a while and then change the functions - you’ve got to remove them. The things using these functions have to fail loudly.

Naming things is hard.