Hello, please have a look at following code snippet
(python 3.4.4)
class Test:

   a = 1

   def __init__(self):
       self.a = 2
       self.f = lambda : print("f from object")
       self.__call__ = lambda : print("__call__ from object")
def __call__(self):
       print("__call__ from class Test")
def f(self):
       print("f from class Test")

test=Test()

test.a
2
ok, a is defined in both the class and the object, it is read from
the object. This is the expected behavior

test.f()
f from object

ok for the same reason

test()
__call__ from class Test


Surprisingly, __call__ from the class is called, not the
one defined in the object. Why ?

Regards
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to