Why no list heritable type?

Robert Brewer fumanchu at amor.org
Thu Dec 16 21:55:41 CET 2004


James Stroud wrote:
> The thread "why not arrays" got me thinking. I would really 
> like to inherit 
> from a list so that I can add methods based on its contents, 
> say if I filled 
> it with a type of object and wanted to iterate over all 
> objects. I have built 
> a wrapper around a list like this for general use:
> 
> class list_of_objects:
>   def __init__(self):
>     self.data = []
>   def __len__(self):
>     return len(self.data)
>   etc ...
> 
> Then it can be heritable and I can add or override methods. 
> Why aren't built 
> in lists and dictionaries real heritable types that can save 
> this kind of patchwork?

They are since Python 2.2 (IIRC):

class mylist(list):
    def mymethod(self):
        self.x = 5

...etc.

What problems are you running into?


FuManChu



More information about the Python-list mailing list