python time
eryksun ()
eryksun at gmail.com
Mon Mar 21 00:33:42 EDT 2011
On Monday, March 21, 2011 12:07:13 AM UTC-4, ecu_jon wrote:
> so then why does this not work ?
>
> import time
> ...
> time = config.get("myvars", "time")
> ...
> while a>0:
> #import time
> time.sleep(2)
>
> if i uncomment the import time line in the while loop it works.
> boggle...
An imported module is an object:
>>> import time
>>> repr(time)
"<module 'time' (built-in)>"
>>> dir(time)
['__doc__', '__name__', '__package__', 'accept2dyear',
'altzone', 'asctime', 'clock', 'ctime', 'daylight',
'gmtime', 'localtime', 'mktime', 'sleep', 'strftime',
'strptime', 'struct_time', 'time', 'timezone', 'tzname']
In Python variables are references to objects. for example, you could do the following:
>>> import time as foo
>>> repr(foo)
"<module 'time' (built-in)>"
>>> dir(foo)
['__doc__', '__name__', '__package__', 'accept2dyear',
'altzone', 'asctime', 'clock', 'ctime', 'daylight',
'gmtime', 'localtime', 'mktime', 'sleep', 'strftime',
'strptime', 'struct_time', 'time', 'timezone', 'tzname']
When you execute 'time = config.get("myvars", "time")', the variable "time" now references a string object instead of the module. Strings don't 'sleep'.
More information about the Python-list
mailing list