[Tutor] subclass of list - one more correction

Gregor Lingl glingl@aon.at
Sat Jan 4 04:03:02 2003


Gregor Lingl schrieb

>
> As an - albeit rather useless ;-)  - example for a classe derived from 
> list, which needs
> the call of the constructor of the superclass ma serve the following:
>
> >>> class shortList(list):
> ...     def __init__(self, aList, maxlen=3):
> ...         self.maxlen = maxlen
> ...         list.__init__(self,aList[-maxlen:])
> ...     def append(self, element):
> ...         list.append(self,element)
> ...         if len(self)>3: 

#  Should read, of course:  if len(self) > self.maxlen:    

>
> ...             return self.pop(0)
> ...
> Sorry. (No more comment, Gregor)