Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Nitpicking - slightly misleading traceback

Reply
Thread Tools

Nitpicking - slightly misleading traceback

 
 
Juho Schultz
Guest
Posts: n/a
 
      01-26-2006
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...
 
Reply With Quote
 
 
 
 
Sybren Stuvel
Guest
Posts: n/a
 
      01-26-2006
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
 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      01-26-2006
Sybren Stuvel <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
Re: nitpicking on face shots A. Cain Computer Support 1 02-26-2004 01:40 AM
Misleading Python error message Brian Kelley Python 4 11-21-2003 08:30 AM
Misleading description of [i:j:k] slicing? Raoul Gough Python 4 08-21-2003 06:07 PM
The term "global variables" misleading? j C Programming 5 07-27-2003 05:16 PM



Advertisments