Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Puzzling error msg. (http://www.velocityreviews.com/forums/t955069-re-puzzling-error-msg.html)

Steven D'Aprano 12-03-2012 06:12 PM

Re: Puzzling error msg.
 
On Mon, 03 Dec 2012 12:37:42 -0500, wrw wrote:

> So far in my experience with Python, it's error messages have been
> clear, concise, and quite good at fingering my errors. However, the
> message below has me stumped. The routine in question has been running
> for weeks with no problems, then yesterday I got the following:
>
> Traceback (most recent call last):
> File "./Connection_Monitor.py", line 146, in <module>
> Google_up, Google_summary, Google_RTT, Google_stddev =

Google.connection_test()
> File "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/

network.py",
> line 101, in connection_test
> #
> IndexError: list index out of range


Are you running Python with the -x option? If so, then I understand that
the line number (and subsequent line of code) reported in tracebacks may
sometimes be off by one.

If not, or if the discrepancy is more than one line, I would start
investigating the following scenario:

* there is a mismatch between the source code .py file and the
byte-code .pyc file;

* but the .pyc file's "last modified date" is newer than the .py file;

* the .pyc file is executed (as is usual);

* but when an error occurs and Python looks up the source file, it
gets something which no longer corresponds to the byte-code being
executed.



By the way, in connection_test you have the following:

> def connection_test(self):
> found_0 = '0 packets received' in ping_result
> found_1 = '1 packets received' in ping_result
> if found_0 == True or found_1 == True:

[...]

Of course that's not correct. You should write:

if (found_0 == True or found_1 == True) == True:

No wait, I mean:

if ((found_0 == True or found_1 == True) == True) == True:

No wait! I meant this:

if ((found_0 == True == True == True == True == ... # Help!
or found_1 == True == True == True == True == ... # Where do I stop?
) == True) == True == True == True == True ... :

*wink*

Of course the whole thing is silly. The right way to test booleans for
their boolean value is just:

if found_0 or found_1:

"flag == True" is the same as "flag".


--
Steven


All times are GMT. The time now is 11:08 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.