Adam Johnson

Home | Blog | Projects | Colophon

How I Import Python's datetime Module


Old Father Datetime

Python’s datetime module risks a whole bunch of name confusion:

For these reasons, I use this import idiom and recommend you do too:

import datetime as dt

Rather than any of:

import datetime
from datetime import datetime  # or time, timezone

Then in your code, dt.datetime, dt.time, and dt.timezone will be unambiguous.


Hope this helps you save time understanding code,


If you found this useful, I'd be grateful if you subscribe to my future posts, via RSS, Twitter, or email:

Or perhaps you'd like to read a related post:

Tags: django, python