My own list object

Jason Orendorff jason at jorendorff.com
Tue Feb 5 20:31:00 EST 2002


MDK writes:
> I am trying to create my own special type of list object.
> 
> However, when I do x.append('yo') it uses Python's append instead 
> of the one from my class.
> 
> If this is not easy can someone at least point me to an example of what I
> want to do?

It is very easy.  But it requires Python 2.2.

class X(list):
    def append(self, something):
        print "Hello, world!"

>>> x = X()
>>> x.append(14)
Hello, world!

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list