Created
January 4, 2016 00:05
-
-
Save Jwely/b8a6c2e74f0d73aea086 to your computer and use it in GitHub Desktop.
example of dynamically calling functions, even class instance methods, with key word arguments.
This file contains 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
__author__ = 'Jwely' | |
class Butt(): | |
def __init__(self): | |
self.times_farted = 0 | |
def fart(self, times): | |
self.times_farted += times | |
print("just farted! that makes {0} times!".format(self.times_farted)) | |
def proxy_function(function, function_kwargs): | |
function(**function_kwargs) | |
if __name__ == "__main__": | |
some_butt = Butt() | |
for i in range(10): | |
proxy_function(some_butt.fart, {'times': 1}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment