471,337 Members | 1,019 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Nitpicking - slightly misleading traceback

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...
Jan 26 '06 #1
2 1131
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
Jan 26 '06 #2
Sybren Stuvel <sy*******@YOURthirdtower.com.imagination> 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
Jan 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian Kelley | last post: by
7 posts views Thread by Robin Becker | last post: by
36 posts views Thread by Hoopster | last post: by
4 posts views Thread by Erik Johnson | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
8 posts views Thread by gregpinero | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.