Re: returning a list: IndexError



shama.bell@xxxxxxxxx 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
.



Relevant Pages

  • Re: dividing by two and rounding up
    ... I have a table I want to lay out dynamcially in rails where if a game ... has 6 periods the first 3 periods will be in the first column and the ... if odd, but that seems kinda a lot of lines for something so simple. ... def test_div_2_round ...
    (comp.lang.ruby)
  • Re: returning a list: IndexError
    ... py> tbl = na.zeros) ... py> def get_value: ... Just as an element of any other container doesn't know what index it's stored at, values in a numarray array don't either. ... STeVe ...
    (comp.lang.python)
  • Re: Macro for calculating
    ... ABC -1,493,802.08 ... DEF -1,877,918.50 ... first column, wherein the names should be same. ... the second column should then be verified and if the second column has a ...
    (microsoft.public.excel.misc)