Is it correct this way to inherit from a list?
gialloporpora
gialloporpora at gmail.com
Sat Mar 2 12:02:14 EST 2013
Hi all,
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 __init__(self, *args):
self._list = list(args)
self._index = 0
def __getitem__(self, key):
return self._list[key]
def __setitem__(self, key, value):
self._list[key] = value
def __len__(self):
return len(self._list)
def __iter__(self):
return self
def next(self):
if self._index == len(self):
self._index = 0
raise StopIteration
next = self._index
self._index += 1
return self[next
Is it correct or it exists another way to inherit from list class?
Sandro
More information about the Python-list
mailing list