Re: Puzzling error msg.

Discussion in 'Python' started by Steven D'Aprano, Dec 3, 2012.

  1. 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
    Steven D'Aprano, Dec 3, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Kelly

    Re: Puzzling error msg.

    Ian Kelly, Dec 3, 2012, in forum: Python
    Replies:
    0
    Views:
    194
    Ian Kelly
    Dec 3, 2012
  2. Chris Angelico

    Re: Puzzling error msg.

    Chris Angelico, Dec 3, 2012, in forum: Python
    Replies:
    0
    Views:
    184
    Chris Angelico
    Dec 3, 2012
  3. Dave Angel

    Re: Puzzling error msg.

    Dave Angel, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    145
    Dave Angel
    Dec 4, 2012
  4. Chris Angelico

    Re: Puzzling error msg.

    Chris Angelico, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    152
    Chris Angelico
    Dec 4, 2012
  5. Dave Angel

    Re: Puzzling error msg.

    Dave Angel, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    155
    Dave Angel
    Dec 4, 2012
Loading...

Share This Page