help - error when trying to call super class method

dontknowwhy88 dontknowwhy88 at yahoo.com
Sun Sep 9 00:50:47 CEST 2007


I am trying to extend list class to build a stack class -- see code below---
but I got an error when I try to call len method from list class here.. why?
Thanks in advance!
---------------------

class Stackx(list):
       
  def push(self,x):      
      indx= super.len(x)
      self.insert(my_len+1,x) 
      
  def pop(self):
      return self[-1]
     
def test():
    
    myStack = Stackx([1, 2 ,3 ,4])
    print myStack
    myStack.push(9)
    print myStack
    print myStack.pop()
    

if __name__=='__main__':
    test()


'''

Traceback (most recent call last):
  File "C:\Python25\Stack2.py", line 20, in <module>
    test()
  File "C:\Python25\Stack2.py", line 14, in test
    myStack.push(9)
  File "C:\Python25\Stack2.py", line 4, in push
    indx= super.len(x)
AttributeError: type object 'super' has no attribute 'len'
'''

       
---------------------------------
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070908/47542803/attachment.html>


More information about the Python-list mailing list