Skip to content

Instantly share code, notes, and snippets.

@mydreambei-ai
Created December 8, 2016 09:35
Show Gist options
  • Save mydreambei-ai/f62f48aef9283e16526aedf57b9b61d4 to your computer and use it in GitHub Desktop.
Save mydreambei-ai/f62f48aef9283e16526aedf57b9b61d4 to your computer and use it in GitHub Desktop.
modify class in running
class Lmy(object):
def sum(self, a, b, c=None):
if c is None:
return a + b
else:
return a + b + c
def do_data(self, data):
a, b = data
return self.sum(a, b)
def new_sum(func, c):
def new_func(a, b):
return func(a, b, c)
return new_func
a = Lmy()
old_sum = a.sum
a.sum = new_sum(old_sum, 5)
a.do_data((1, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment