Datetime 1 of 6


This lesson just says Run to continue, there is only “from datetime import datetime” in python script in the editor.

The instructions say “Click Run to continue”, but when i click - nothing appears to happen. I would expect something, anything to happen that would provide feedback. If the script just loads a module/information/variable into memory, then maybe the script should still have some feedback to let me know that is what’s going on. Otherwise it’s not clear if this thing is broken, working as intended or anything in between.


Hi @switcharoo,

Most modules do not announce anything when we import them. If you want to find out what was loaded by the import, you can do something like this …

from datetime import datetime
print dir(datetime)

Output …

['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']

Among the methods and other objects in the list that got displayed is now, a method that is called in the exercises that follow.

Here’s a module that does announce something upon its importation …

import this

Output …

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.