TypeError: unsubscriptable object.
Terry Reedy
tjreedy at udel.edu
Fri May 21 18:56:59 EDT 2004
"Balaji" <balaji at email.arizona.edu> wrote in message
news:494182a9.0405211340.49873a72 at posting.google.com...
> class Stack:
>
> def __init__(self,expr):
Note: tabs get eaten by some newsreaders.
> self.stackP=[]
> self.stackF=1
...
> def peekF(self):
> rval = 0 # useless line
> rval= self.stackF[-1]
> return rval
# return self.stackF[-1] would be easier to read
See the potential problem? (If not, add
'print type(self.stackF)' to the top of this function.)
> def stackManagement(self,expr):
...
> self.a+= self.peekF()
which now seems quite possible.
...
> s.stackManagement(e1)
> ----------------------------------------------
> I'm getting the following error TypeError: unsubscriptable object...
which means you tried to subscript an unsubscriptable object
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "generation.py", line 175, in stackManagement
> self.stackManagement(expr.left)
> File "generation.py", line 176, in stackManagement
> self.stackManagement(expr.right)
> File "generation.py", line 199, in stackManagement
> self.a+= self.peekF()
> File "generation.py", line 168, in peekF
> rval= self.stackF[-1]
in the line immediately above.
Terry J. Reedy
More information about the Python-list
mailing list