AttributeError: ClassA instance has no attribute '__len__' martin.witte at
Wed Mar 30 22:01:06 CEST 2005

The most simple way to get this error I can think of is like this. It
happens because len does not know how to calculate the lenght of this
-class classA:
-   def __init__(self):
-       pass

-a = classA()
-print len (a)

Traceback (most recent call last):
  File "./", line 10, in ?
    print len (a)
AttributeError: classA instance has no attribute '__len__'

You can fix it by adding a __len__ method:
class classA:
    def __init__(self):

    def __len__(self):
        return 0

a = classA()
print len (a)


More information about the Python-list mailing list