Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Dan Oswalt
23,438 Pointsdatetime.datetime question question
Why don't we say "from datetime import datetime?" so we don't have to type datetime.datetime each go around? I'm sure I'm missing something, so fill me in.
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsUsing from datetime import datetime is equally as valid.
The difference is how one likes to manage their namespaces.
Some like to only import modules then refer to functions using module.function. For large programs with many imports, this helps keep track of where the function came from without having to scroll to the top of the code.
Using the module name as a function prefix also prevents collisions if importing to functions with the same name.
The bottom line is either is fine as long as the code readability doesn't suffer.
Dan Oswalt
23,438 PointsDan Oswalt
23,438 PointsThanks Chris, that's a great explanation.