Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created September 13, 2011 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save missingfaktor/1214994 to your computer and use it in GitHub Desktop.
Save missingfaktor/1214994 to your computer and use it in GitHub Desktop.
Python reflection magic
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