changing a list within a subclass of list ?

Mark McEahern marklists at mceahern.com
Thu Oct 10 17:19:16 EDT 2002


> Hello, I don't understand one aspect of builtin-types 
> subclassing. Assume I have subclassed a list:
> 
> 	class Mylist(list):
> 		pass
> 
> and would like to do something like:
> 
> 	l=Mylist([1,2,3])
> 
> instead of 
> 
> 	l=[1,2,3] 
> 
> for a standard list. What should I put in the constructor?

Do you need an __init__ method at all?

$ python
Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyList(list):pass
...
>>> l = MyList([1, 2, 3])
>>> l
[1, 2, 3]
>>>

// m
-





More information about the Python-list mailing list