Skip to content

Instantly share code, notes, and snippets.

@Jwely
Created January 4, 2016 00:05
Show Gist options
  • Save Jwely/b8a6c2e74f0d73aea086 to your computer and use it in GitHub Desktop.
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.
__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