dontknowwhy88
Technical User
- Sep 8, 2007
- 1
- 0
- 0
I am new to Python.
I am writing a Stack class (extending list class) to perform push and pop.
However, when I try to call 'len' function from super class, I got an error msg --
AttributeError: type object 'super' has no attribute 'len'
Please help!!!
Thanks in advance!!
-here is my code -
------------------------
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'
'''
I am writing a Stack class (extending list class) to perform push and pop.
However, when I try to call 'len' function from super class, I got an error msg --
AttributeError: type object 'super' has no attribute 'len'
Please help!!!
Thanks in advance!!
-here is my code -
------------------------
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'
'''