Guest User

Untitled

a guest
Dec 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. import types
  2. class A():
  3. def __init__(self):
  4. self.a = 0
  5.  
  6. def print(self, v):
  7. print(self.a + v)
  8.  
  9. def override_print(self, fn):
  10. self.print = types.MethodType(fn, self)
  11.  
  12.  
  13. def new_print(self, value):
  14. print(self.a + value * 2)
  15.  
  16.  
  17. a = A()
  18. a.override_print(new_print)
  19. a.print(10)
Add Comment
Please, Sign In to add comment