How to deal __getattr__

limodou limodou at gmail.com
Sat Oct 16 07:59:11 CEST 2004


I found it puzzled me that:

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

__eq__

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in -toplevel-
    a==b
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__?

Thankx

-- 
I like python!



More information about the Python-list mailing list