473,698 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nitpicking - slightly misleading traceback

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

Traceback (most recent call last):
File "reduce.py" , line 524, in remove_badvalue s
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_ke y(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 1213
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_ke y(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*******@YOUR thirdtower.com. imagination> wrote:
...
if data[x][y] > 0 or datadict.has_ke y(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2211
by: Brian Kelley | last post by:
I accidentally derived a class from a module (types instead of types.Dicttype) >>> import types >>> class f(types): pass .... Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: function takes at most 2 arguments (3 given)
7
2232
by: Robin Becker | last post by:
def raise_an_error(): a = 3 b = 4 c = 0 try: a = a/c except: import sys, cgitb, traceback, inspect tbt,tbv,tb = sys.exc_info() print 'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
36
2849
by: Hoopster | last post by:
Hello, I know nothing about C++ but want to get started. Is there any good free C++ program that I can try to see if I like programming? I also need a good free compiler. I don't want to purchased the regular VB C++ until I know that I will like it.
3
2481
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as a QA in an MNC in India, since I graduated in September 2003. I am working in a QA role which requires me to do some Winrunner automation, and modifying/creating a framework in Perl for Automated Regression Testing of some command Line utilities...
8
2128
by: Claudio Grondi | last post by:
Here an example of what I mean (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte large file): Traceback (most recent call last): File "<pyshell#1>", line 1, in -toplevel- f = file('veryBigFile.dat','r+') IOError: No such file or directory: 'veryBigFile.dat'
5
7667
by: jkn | last post by:
Hi all Python 2.4.2 (#1, Apr 26 2006, 23:35:31) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: invalid mode: a
4
11028
by: Erik Johnson | last post by:
I ran into a problem I didn't understand at first. I got part of it figured out. Let me first demonstrate the original problem: class Super(object): def __init__(self): self._class = 'Super' def hello(self): print "%s says 'Hello'" % self._class
232
13253
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
8
1999
by: gregpinero | last post by:
I'm running code via the "exec in context" statement within a much larger program. What I would like to do is capture any possible errors and show a pretty traceback just like the Python interactive interpreter does, but only show the part of the traceback relating to the code sent to exec. For example here is the code I'm using: try: exec code
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.