Here is a solution with a decorator:
from functools import wraps
from inspect import getcallargs
def defaults_from_globals(f):
@wraps(f)
def new(**kwargs):
# filter only those vars, that are in the list of function's named args
from_globals = {arg: globals()[arg] for arg in getcallargs(f)}
# overwrite them with user supplied kwargs
from_globals.update(kwargs)
return f(**from_gobals)
return new
@defaults_from_globals
def f(a=None, b=None, c=None):
return a, b, c
a = 1
b = 2
c = 3
print f(a=2, b=4) # 2 4 3