Created
December 8, 2016 09:35
-
-
Save mydreambei-ai/f62f48aef9283e16526aedf57b9b61d4 to your computer and use it in GitHub Desktop.
modify class in running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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