returning a list: IndexError

Steven Bethard steven.bethard at gmail.com
Wed Mar 30 20:13:10 EST 2005


shama.bell at gmail.com wrote:
> from Numeric import *
> 
> # Initialize the 32x16 global array to zeros
> tbl = zeros((32, 16)
> 
> def getValue( value):
>     data = test(value)
>     c1 = data[0]
>     c2 = data[1]
>     print tbl[c1, c2]
> 
> def test( value):
>     t1 = 0x0
>     t2 = 0x1
>     return tbl[t1, t2]

In test, tbl[0x0, 0x1] is just going to give you a single element of 
tbl, in this case a 0.  So data is a 0.  data[0] and data[1] doesn't 
really make much sense.  Is this the code you actually get the 
IndexError with?  I'm using numarray, not Numeric, and I know there are 
some differences, but the code above doesn't give me an IndexError:

py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def get_value():
...     data = test()
...     c1 = data[0]
...     c2 = data[1]
...     print tbl[c1, c2]
...
py> def test():
...     t1 = 0x0
...     t2 = 0x1
...     return tbl[t1, t2]
...
py> get_value()
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
   File "<interactive input>", line 3, in get_value
TypeError: unsubscriptable object

STeVe



More information about the Python-list mailing list