python time

Ulrich Eckhardt doomster at knuut.de
Mon Mar 21 03:02:49 EDT 2011


ecu_jon wrote:
> import time,os,string,getpass,md5,ConfigParser
> from time import strftime,localtime


You are importing the time module first, then import some symbols from the 
time module. This seems redundant to me. Note that after the "import 
time", the name "time" refers to the module you imported...

> time = config.get("myvars", "time")

...but after this line it refers to something else, because you rebound it 
to the object returned by "config.get(...)".

> #print "date is ",date , " time is ",time
> a=1
> while a>0:

Note: PEP8 actually say you shall use spaces around operators here.

>     #import time

You're on the right track...

>     time.sleep(2)

...because this time here doesn't refer to the time module but to the 
output of "config.get(...)"! This object is a string object (type "str"), 
and Python complains:

> AttributeError: 'str' object has no attribute 'sleep'


I Hope that clarifies something! ;)

Uli





More information about the Python-list mailing list