Created
September 13, 2011 20:12
-
-
Save missingfaktor/1214994 to your computer and use it in GitHub Desktop.
Python reflection magic
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
import inspect | |
def call(fun, **myArgs): | |
names, _, _, values = inspect.getargspec(builder) | |
defaults = zip(names, values) | |
valuesToCallWith = dict(defaults + myArgs.items()) | |
return fun(**valuesToCallWith) | |
def builder(a = 0, b = 2, c = 3): | |
return a + b + c | |
print call(builder, a = 3) # prints 8 | |
print call(builder, b = 9, c = 1) # prints 10 | |
print call(builder, c = 11) # prints 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment