How to deal __getattr__

limodou limodou at
Sat Oct 16 07:59:11 CEST 2004

I found it puzzled me that:

class A:
    def __getattr__(self, name):
        return None
a==b will raise Exception:


Traceback (most recent call last):
  File "<pyshell#7>", line 1, in -toplevel-
TypeError: 'NoneType' object is not callable

I want to compare the objects themself not the attributes of them. But
it seems python invoke __getattr__ method, it's strange. How can I
compare the object directly without calling __getattr__?


I like python!

More information about the Python-list mailing list