Created
October 20, 2017 22:33
-
-
Save ajp619/8cfaf387d6e742cdb2ee29acfc279bfc to your computer and use it in GitHub Desktop.
python decorator to pre-populate key word arguments
This file contains hidden or 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
def decorator_generator(**kw_dict): | |
def decorator(fun): | |
def decorated(*args, **kwargs): | |
kwargs.update(kw_dict) | |
return fun(*args, **kwargs) | |
return decorated | |
return decorator | |
@decorator_generator(c=3) | |
def foo(a, c): | |
return 2*a + c*c | |
foo(2) | |
# 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment