Overriding UserList methods

Thomas Wouters thomas at xs4all.net
Mon Mar 5 16:33:44 CET 2001

On Sun, Mar 04, 2001 at 10:35:27PM -0800, Daniel Klein wrote:
> I found the answer in the Beazley book. It's

> def append(self, object):
>         self.data.append(object)

> using the 'data' instance variable automatically set up in the UserList
> class. But I'll try the other suggestions anyway just to get a better
> understanding.

Note that though this method is 'allowed' with UserList instances (because
'data' is not a private variable) it does break the encapsulation. If you
were to change your class to derive from OtherModule.ExtendedUserList, which
did some extra funky stuff before/after really appending to the data, you
wouldn't get the new functionality. If you just used
'UserList.UserList.append(self, data)', you would, though you would have to
remember to change all references from 'UserList.UserList' to

Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list