Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from types import MethodType
- class MyObj(object):
- def __init__(self, val):
- self.val = val
- def new_method(self, value):
- return self.val + value
- obj = MyObj(3)
- # only works for obj
- obj.method = MethodType(new_method, obj, MyObj)
- MyObj.method = MethodType(new_method, None, MyObj)
Add Comment
Please, Sign In to add comment