0

I have an array already initialized to be a 3x6 array called self.ascii. I am trying alter a 3x3 block of this array at a time, using the code:

for x in range(3):
    for y in range(3):
       # currY and currX represent the bottom left corner of the 3x3 square I am tyring to alter
       self.ascii[y+currY][x+currX] = arr[y][x] # yes I know the x and y values are backwards between the arrays

However I keep getting the error, in GNURadio-Companion list index out of range--before I even try to run it. I know that the indexes here do not leave the range of the list.

Question: Why does python check this before running, and is there a different way I should be loading these 3x3 arrays

Trov4
  • 21
  • 2
  • 2
    Can you post the traceback message that shows the failing line? Python doesn't check list indexes before you run it, so something else is going on. Printing `self.ascii`, plus `currY` and `currX` would be useful. One of these is different than you think. – tdelaney Apr 10 '20 at 03:40
  • 1
    Maybe `2+currY > your length of one dimension`. – jizhihaoSAMA Apr 10 '20 at 03:42
  • If `currY` is bottom left, then the rows you want are `currY-0`, `currY-1` and `currY-2`, but you are adding postive numbers here. Perhaps you want `self.ascii[currY-y][currX+x]` or maybe since you use y on both sides, `self.ascii[currY-3+y]` – tdelaney Apr 10 '20 at 03:54

1 Answers1

1

Learn to use pdb.

import pdb

pdb.set_trace()

# Now your code.
for x in range(3):
    for y in range(3):
       self.ascii[y+currY][x+currX] = arr[y][x]

This will drop you into an interpreter where you can see the value of anything you like, and use commands like n to execute the next instruction in the code. Go step by step until you find which index is going outside the range of its list.

Chris
  • 6,805
  • 3
  • 35
  • 50