Adam Johnson

Home | Blog | Training | Projects | Colophon | Contact

How I Import Python's datetime Module

2019-09-12 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.

Fin

Hope this helps you save time understanding code,

—Adam


Are your Django project's tests slow? Read Speed Up Your Django Tests now!


Subscribe via RSS, Twitter, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: django, python