new-style classes and len method

Thomas Girod girodt at gmail.com
Thu Apr 13 10:02:41 EDT 2006


Hi there.

I'm trying to use new-style classes, but there is something i'm
obviously missing

here it is :

class Data(list):
    __slots__ = ["width", "height", "label"]

    def __init__(self,width,height,label=None):
        list.__init__(self)
        self.width = width
        self.height = height
        self.label = label

    def clear(cls):
        while len(cls) > 0: del cls[0]
        return
    clear = classmethod(clear)

#> d = Data(2,2)
#> d.clear()
TypeError: len() of unsized object

off course it was working with :

[...]
    def clear(self):
        while len(self) > 0: del self[0]
        return

So, I guess you can't use "cls" as a replacement for "self". So, what
do I have to use ???




More information about the Python-list mailing list