faqts : Computers : Programming : Languages : Python : Common Problems : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

I'd like to create a subclass of list that loads its contents from a file when you instantiate it. What do I subclass to do this?

Sep 29th, 2002 06:58
Joel Burton, unknown unknown, Remco Gerlich


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).


Update for Python 2.2: with type/class integration, you can now 
subclass 'list' directly.