help - error when trying to call super class method

Matt McCredie mccredie at gmail.com
Mon Sep 10 07:29:38 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!

Jeff did a good job of answering your questions. I just wanted to note
that your pop is broken, but that doesn't matter since list already
has a pop method that will do what you want. Actually it has a push
method that does what you want too, it is called `append'. If you
really want a push method, you could just do this:

[code]
>>> class Stack(list):
...     push = list.append
>>> s = Stack()
>>> s.push(1)
>>> s.push(2)
>>> s.push(3)
>>> s.pop()
3
>>> s.pop()
2
>>> s.pop()
1
[/code]

Matt



More information about the Python-list mailing list