Can anyone spot my float error?

Richard Harvey tririch at connect.net
Sat Sep 2 01:25:29 CEST 2000


Alex, Alain, and Grant:

Thanks very much for the sanity check.  I just found the error from a very
strange source. This function is being called from C through the Python C
API.  It just so happens that Python was reporting an error when compiling
this source, but it did nothing with the error (nor did I correctly call
PyErr_Clear). So, the first time I call this function (after the compile
stage) the 'if' statement is the first place the Python interpretter hits a
block of code internally that checks the status of the PyErr... It
mistakenly thinks the error was caused by the 'if', when really it was a
preprocessing error when compiling the file. Now, why it reported the error
but still compiled and saved the .pyc file I'm not sure yet, but calling
PyErr_Clear after the compile solved the problem.

Rich

Alex Martelli <aleaxit at yahoo.com> wrote in message
news:8op7j30dhn at news2.newsguy.com...
> "Richard Harvey" <tririch at connect.net> wrote in message
> news:IZSr5.8460$Jq2.15065 at dfw-read.news.verio.net...
> > 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
>
> I can't reproduce your problem.  Saving this code in Script1.py,
> importing it, and running:
>
> >>> for i in range(23):
> ...  Script1.testFunc()
> ...
>
> I obtain the output:
>
> timer > 10
> timer > 10
> timer > 10
> >>>
>
> just as expected.  What's your Python build...?
>
>
> Alex
>
>
>





More information about the Python-list mailing list