AttributeError: ClassA instance has no attribute '__len__'

MackS mackstevenson at hotmail.com
Wed Mar 30 13:59:12 EST 2005


I'm new to Python. In general I manage to understand what is happening
when things go wrong. However, the small program I am writing now fails
with the following message:

AttributeError: ClassA instance has no attribute '__len__'

Following the traceback,I see that the offending line is

self.x = arg1 + len(self.y) + 1

Why should this call to the built-in len() fail? In a small test
program it works with no problems:

class foo:
  def __init__(self):
    self.x = 0
    self.y = 'y'

  def fun(self, arg1):
      self.x = arg1 + len(self.y) + 1

>>> a = foo()
>>> a.fun(2)
>>>

No problems; can you help me make some sense of what is happening?

Thanks in advance

Mack




More information about the Python-list mailing list