Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A(object):
- def test(self):
- return "Tset"
- def __call__(self):
- return "Eaxmple"
- a = A()
- print("call method: {0}".format(a.__call__))
- print("test method: {0}".format(a.test))
- a.__call__ = lambda : "Example"
- a.test = lambda : "Test"
- print("call method: {0}".format(a.__call__))
- print("test method: {0}".format(a.test))
- print(a())
- print("Explicit call: {0}".format(a.__call__()))
- print(a.test())
- call method: <bound method A.__call__ of <__main__.A object at 0x7f3f2d60b6a0>>
- test method: <bound method A.test of <__main__.A object at 0x7f3f2d60b6a0>>
- call method: <function <lambda> at 0x7f3f2ef4ef28>
- test method: <function <lambda> at 0x7f3f2d5f8f28>
- Eaxmple
- Explicit call: Example
- Test
- ...
- Example
- Explicit call: Example
- Test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement