returning a list: IndexError

Steven Bethard steven.bethard at gmail.com
Thu Mar 31 00:31:57 EST 2005


shama.bell at gmail.com wrote:
> Steven Bethard wrote:
>>
>>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
> 
> What i was intending to do is return a list with row and column values.
> 
> data[0] and data[1] are the list values i get from test.
> 
> Whats the best way to read these row and column values in function
> get_value() when i return the list (return tbl[t1, t2])

Still not sure I understand you.  Are you wanting c1 and c2 to retrieve 
the values that t1 and t2 had?  (That is, 0x0 and 0x1?)  Or do you want 
c1 and c2 to hold the first row and the first column?  Or something else?

STeVe



More information about the Python-list mailing list