[Tutor] please help debug

Emil Styrke emil@lysator.liu.se
07 Jul 2002 16:56:50 +0200


"Kyle Babich" <kb@kb5.org> writes:

> I'm writing a program that tracks each hour spent on the computer for
> my parents but I can't get hour() to execute, and time.sleep() won't
> sleep.  Can someone please help me fix these problems?
> 
> Here is what I wrote so far:
> 
> #! C:\Python22\python.exe
> 
> import time
> time = time.strftime( "%I:%M:%S %Z", time.localtime(time.time()) )

You should use another name for this variable, it collides with the
time module.


> def hour():
> 	print "The current time is %(time)s" % vars()

This fails because time doesn't exist in vars(), it only contains
local variables.  Try using globals() instead.  Better yet, move the
global assignment into the function.


        /Emil