Python Tip #257 (of 365): Consider "import datetime as dt". The fact that the da...

@treyhunner@mastodon.social

Python Tip #257 (of 365):

Consider "import datetime as dt".

The fact that the datetime module and the datetime class are spelled the same way is VERY confusing.

You could use a "from" import:

from datetime import datetime

Now datetime means the class.

But if later on you also want the date class, you're importing that name too, and hoping no local date variable ever shadows it. I definitely use the variable name date, so this is a problem for me.

๐Ÿงต (1/3)

#Python #DailyPythonTip