November 25th, 2012, 06:10 PM
Question about modules
Why do I need "from datetime import datetime" in the following code?
from datetime import datetime
hour = datetime.time(datetime.now()).hour
minute = datetime.time(datetime.now()).minute
second = datetime.time(datetime.now()).second
milisecond = datetime.time(datetime.now()).microsecond/1000
return hour, minute, second, milisecond
I know it won't work without it, but why is that? I tried with only import datetime, it didn't work.
Thanks for the reply in advance
November 25th, 2012, 10:14 PM
This module looks screwy, but I didn't read the manual. The datetime you imported is a class in the datetime module. Why a constructor for objects of class datetime class is hidden in a method of the class I cannot say.
o = datetime.datetime.today() # construct a datetime instance of now
[/code] are essential for python code and Makefiles!