Nitpicking - slightly misleading traceback

Discussion in 'Python' started by Juho Schultz, Jan 26, 2006.

  1. Juho Schultz

    Juho Schultz Guest

    if ((data[x][y] > 0) or
    (datadict.has_key[key])):

    Traceback (most recent call last):
    File "reduce.py", line 524, in remove_badvalues
    if ((data[x][y] > 0) or
    TypeError: unsubscriptable object

    However, the bug sits on the next line. I used square brackets when
    normal brackets were needed - should have written datadict.has_key(key)
    as the old code had datadict[key]. In the real code variable names are
    so long that I must split the line. I feel the traceback is misleading.

    I guess the best solution is to write code without bugs...
     
    Juho Schultz, Jan 26, 2006
    #1
    1. Advertising

  2. Juho Schultz enlightened us with:
    > However, the bug sits on the next line. [...] I feel the traceback
    > is misleading.


    Well, the bug sits in the command starting on the line indicated.

    Nitpick back: Learn about operator precedence and Python syntax rules.
    You don't need so many brackets:

    if data[x][y] > 0 or datadict.has_key(key):

    This might even make things fit on one line again ;-)

    Sybren
    --
    The problem with the world is stupidity. Not saying there should be a
    capital punishment for stupidity, but why don't we just take the
    safety labels off of everything and let the problem solve itself?
    Frank Zappa
     
    Sybren Stuvel, Jan 26, 2006
    #2
    1. Advertising

  3. Sybren Stuvel <> wrote:
    ...
    > if data[x][y] > 0 or datadict.has_key(key):
    >
    > This might even make things fit on one line again ;-)


    Particularly if you code it idiomatically:

    if data[x][y] > 0 or key in datadict:


    Alex
     
    Alex Martelli, Jan 26, 2006
    #3
    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. j
    Replies:
    5
    Views:
    418
    Samuel Barber
    Jul 27, 2003
  2. Raoul Gough
    Replies:
    4
    Views:
    328
    Raoul Gough
    Aug 21, 2003
  3. Brian Kelley

    Misleading Python error message

    Brian Kelley, Nov 19, 2003, in forum: Python
    Replies:
    4
    Views:
    372
    Dennis Lee Bieber
    Nov 21, 2003
  4. misleading prefix ++

    , May 20, 2006, in forum: Python
    Replies:
    6
    Views:
    377
    Carl Friedrich Bolz
    May 21, 2006
  5. Jack Bates
    Replies:
    0
    Views:
    284
    Jack Bates
    May 2, 2011
Loading...

Share This Page