Overriding UserList methods
chris.gonnerman at usa.net
Wed Mar 7 03:31:40 CET 2001
----- Original Message -----
From: "Daniel Klein" <danielk at aracnet.com>
Subject: Re: Overriding UserList methods
> On Mon, 5 Mar 2001 00:52:40 -0500, "Steve Holden" <sholden at holdenweb.com>
> >"Daniel Klein" <danielk at aracnet.com> wrote in message
> >news:b566atck0ruu4tae8n1srrkntbmme26gor at 4ax.com...
> >> I must be missing something, cos I can't figure out how to override a
> >> using the UserList module. Here is some code:
> >> import UserList
> >> class MyList(UserList.UserList):
> >> __def __init__(self):
> >> UserList.UserList.__init__(self)
> >While this would work, I don't see it's strictly necessary. Why not just
> >inherit the __init__ method from UserList?
> One of the reasons for subclassing UserList is to provide additional
> variables. So I need my own __init__ method to initialize this, don't I?
Nope. Only if you *actually* initialize them in the __init__ method, which
you aren't doing.
I wrote a module a while back that subclasses UserDict... not exactly the
problem but close enough to help. If you are interested, visit
and download the Chunk.py module.
Remember that when you call a method of an instance variable, i.e.:
from UserList import UserList
lst = UserList()
what is (effectively) called is:
def append(self, item):
is the "right" way to do it. Of course, you can also just use the .append()
method of the underlying .data element, but I prefer to use the "proper"
More information about the Python-list