Error
J. Cliff Dyer
jcd at sdf.lonestar.org
Tue Oct 21 11:47:16 EDT 2008
On Tue, 2008-10-21 at 09:34 -0400, Philip Semanchuk wrote:
> On Oct 21, 2008, at 9:05 AM, Amie wrote:
>
> > Hi,
> >
> > what does is the meaning of this error: int object is unsubscriptable.
> > This is the code that I have written that seems to give me that:
> >
> > def render_sideMenu(self, ctx, data):
> > def render_dataAge(unit):
> > results = [(i[0], i[1]
> > ) for i in unit]
> > return self.dataTable(["Unit Name", "Current Data Age"],
> > results, sortable=True),
> > return
> > self
> > .enamel
> > .,storage
> > .getDataAge(int(self.arguments[0])).addCallback(render_dataAge)
>
> I can't see all of your code so I'm not sure, but it sounds like
> you're treating a plain int object as if it was a sequence (like a
> list or a tuple). My guess is that "i" in the code above is an int.
> Try this Python code in the interpreter and you'll get the same error:
>
> >>> 1[0]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'int' object is unsubscriptable
> >>>
>
> -- OR --
>
> >>> i = 1
> >>> i[0]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'int' object is unsubscriptable
> >>>
>
Indeed. In other words, unit is a list (or other iterable) of integers.
It looks like you want it to be a list of tuples of some kind.
>>> unit = [('inch', 4), ('pound', 16), ('yottabyte', 2)]
>>> [i[0] for i in unit]
['inch', 'pound', 'yottabyte']
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list