Looking for a list subclassing example...

Darrell dgallion1 at yahoo.com
Tue Jun 4 12:33:08 EDT 2002


class Seq(list):
    """ list with key words """
    def __init__(self, *v, **kw):
        list.extend(self, v)
        for k,v in kw.items():
            setattr(self, k, v)

class LimitList(list):
    """ list limited in size """
    def __init__(self, limit):
        self.limit=limit
    def append(self, item):
        list.append(self, item)
        diff =  len(self) - self.limit
        if diff == 1:
            del self[0]
        else:
            self = self[-self.limit:]

--Darrell
"Shagshag13" <shagshag13 at yahoo.fr> wrote in message news:<adi4dv$118tko$1 at ID-146704.news.dfncis.de>...
> Hello,
> 
> I'm looking for a list subclassing example, and i can't find it...
> 
> Do you have one to show ?
> 
> Thanks,
> 
> s13.



More information about the Python-list mailing list