Guest User

Untitled

a guest
Jun 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. from types import MethodType
  2.  
  3. class MyObj(object):
  4. def __init__(self, val):
  5. self.val = val
  6.  
  7. def new_method(self, value):
  8. return self.val + value
  9.  
  10. obj = MyObj(3)
  11. # only works for obj
  12. obj.method = MethodType(new_method, obj, MyObj)
  13.  
  14. MyObj.method = MethodType(new_method, None, MyObj)
Add Comment
Please, Sign In to add comment