I’m having some issues filling a list in Python. I keep getting a list index out of range error. The output of len(network) is 7 so I figured filling it from 0-6 should work to give me a 7×7 list.
def fillNodeTable():
nodeTable = []
for x in xrange(0, (len(network) -1)):
for y in xrange(0, (len(network) -1)):
nodeTable[x][y].append(Node)
print nodeTable
So I ended up with this and it works
n = len(network)
nodeTable = [[Node]*n for x in xrange(n)]
When I print the nodeTable to debug I get the following:
<class __main__.Node at 0xb737914c>
Is this just because I’m appending a class to each entry or have I done something else wrong here?
I think you are porting a MATLAB code. You are getting the out of range error on nodeTable. You initialize it to an empty array.
Try something like this, or use the array classes in numpy:
or