[Tutor] 2d list index inverting?

Hugo Arts hugo.yoshi at gmail.com
Wed May 26 04:14:58 CEST 2010


On Wed, May 26, 2010 at 3:47 AM, Alex Hall <mehgcap at gmail.com> wrote:
>
> I thought so, but I was hoping you would not say that as this means a
> logic bug deep in my code, and those are the hardest to track down...

Unfortunately, yes. Bug hunting is part art, part science.

>> The real problem is something else entirely. Somewhere in your code,
>> you are using an index that is greater than the size of the list.
>
> Yes, and it looks like my coordinates are bing reversed somewhere, but
> I cannot find anywhere where that is happening in the code.

This is a good thing. You already have some idea of what is happening.
Confirm your suspicions, then work from there.

>> Perhaps you're not consistent, somewhere. Mixing up your row/column
>> order. Perhaps something else is amiss. No way to tell from the
>> snippet.
> So, a lot of print() statements then...

It's a good start. I suggest you begin at the place where the error
occurs, then work your way back slowly. verify at each point that your
data is mixed up, until you find what introduced the mixup.

There are other some other useful tools. The python debugger might be
of some help. http://docs.python.org/library/pdb.html
It's especially useful to gain more insight in what precisely a piece
of code is doing. There is a learning curve to it, but once you know
how to use it it will pay back many times over.

I think you'll have this bug resolved soon enough by yourself, but
should you get the urge to bang your head against a wall repeatedly,
come back here and we'll have a closer look at it. Good luck and happy
hunting,

Hugo


More information about the Tutor mailing list