Is it correct this way to inherit from a list?

Peter Otten __peter__ at
Sat Mar 2 18:19:29 CET 2013

gialloporpora wrote:

> I would like to inherit from the list native class.
> really I expected that was possible to use native list method without
> redefining them, for example the __repr__ method.
> I don't know if i have made something wrong, this is my code (I obmit
> customized methods that I have added):
> from os.path import exists
> class vector(list):

> def __getitem__(self, key):
>     return self._list[key]

[and many more]

> Is it correct or it exists another way to inherit from list class?

Have you considered subclassing collections.MutableSequence instead?
You cannot instantiate that class until you have overridden all its abstract 

More information about the Python-list mailing list