Can anyone spot my float error?

Alain TESIO alain at onesite.org
Fri Sep 1 22:49:41 CEST 2000


Very strange, it works fine for me, with 1.5.2
I tested with the windows binary, and linux redhat 5.2 compiled from the tarball.

Alain

On Fri, 1 Sep 2000 14:00:28 -0500, "Richard Harvey" <tririch at connect.net> wrote:

>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