Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class A(object):
  2. def test(self):
  3. return "Tset"
  4.  
  5. def __call__(self):
  6. return "Eaxmple"
  7.  
  8. a = A()
  9. print("call method: {0}".format(a.__call__))
  10. print("test method: {0}".format(a.test))
  11. a.__call__ = lambda : "Example"
  12. a.test = lambda : "Test"
  13. print("call method: {0}".format(a.__call__))
  14. print("test method: {0}".format(a.test))
  15.  
  16. print(a())
  17. print("Explicit call: {0}".format(a.__call__()))
  18. print(a.test())
  19.  
  20. call method: <bound method A.__call__ of <__main__.A object at 0x7f3f2d60b6a0>>
  21. test method: <bound method A.test of <__main__.A object at 0x7f3f2d60b6a0>>
  22. call method: <function <lambda> at 0x7f3f2ef4ef28>
  23. test method: <function <lambda> at 0x7f3f2d5f8f28>
  24. Eaxmple
  25. Explicit call: Example
  26. Test
  27.  
  28. ...
  29. Example
  30. Explicit call: Example
  31. Test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement