Subclass List

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Wed May 31 06:50:32 EDT 2000


Chris Withers wrote in comp.lang.python:
> I'd like to create a subclass of list that loads it's contents from a
> file when you instantiate it.
> 
> What do I subclass to do this? I tried 'List' and 'ListType' but got
> NameError's.

You can't directly subclass types, like lists and integers. This is commonly
viewed as a flaw in Python, maybe this will be changed once.

However, you can subclass UserList.UserList, a Python wrapper around a list
(see Lib/UserList.py for its source).

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
  Murphy's Rules, "Heavy-Duty Rapid Fire":
   In Traveler (GDW) a spaceship's weapons can fire only once every
   sixteen minutes. Most battles last several hours.



More information about the Python-list mailing list