Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
I'm not clear on when I need to write datetime.what_I_want() vs datetime.datetime.what_I_want(). Is there a rule?
For example, datetime.timedelta as opposed to datetime.datetime.fromtimestamp, as seen in the previous challenge.
Jennifer NordellTreehouse Teacher
Hi there, Farah Hassan! It depends on how you imported
If you did this:
... then you will need to use
datetime.timedelta for example.
But if you did this:
from datetime import datetime, timedelta
... then you would only need
The first one imports the entire datetime.py module which contains other things besides the
datetime. So to access anything in it you need
datetime.datetime because there are also things like
Hope this helps!
edited for accuracy
I originally posted an answer that was a bit incorrect. The
timedelta is a part of the datetime library, not the datetime object in the datetime library. The datetime library contains an object that is also called