Can anyone spot my float error?
Richard Harvey
tririch at connect.net
Fri Sep 1 15:00:28 EDT 2000
I'm seeing an extrememly wacky effect in 1.5.2, and the code is so simple
I'm baffled that I cannot see the error. Here is a snippet:
timer = 0.0
def testFunc():
global timer
timer = timer + 0.5
if timer > 10.0:
print "timer > 10"
If I repeatedly call testFunc in a loop, my print statement never gets
called. However, if I change the code to the following everything works
fine:
timer = 0.0
def testFunc():
global timer
timer = timer + 0.5
dummy = "timer is %s" % str(timer)
if timer > 10.0:
print "timer > 10"
In this case, my if statement becomes true as expected. I've tried calling
isinstance(timer,FloatType), and it returns true. Also, if I change the
dummy line to:
dummy = "timer is %f" % timer
the code no longer works; dummy does not get assigned, and my if statement
is never true. Arrrghh!!
Rich
More information about the Python-list
mailing list