Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import types
- class A():
- def __init__(self):
- self.a = 0
- def print(self, v):
- print(self.a + v)
- def override_print(self, fn):
- self.print = types.MethodType(fn, self)
- def new_print(self, value):
- print(self.a + value * 2)
- a = A()
- a.override_print(new_print)
- a.print(10)
Add Comment
Please, Sign In to add comment