Created
September 12, 2018 17:40
-
-
Save u8sand/e424d6a05752b7a58da9b48ee9e0b6fa to your computer and use it in GitHub Desktop.
Bind positional and named arguments to function, creating a new function in python
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 bind(func, *args, **kwargs): | |
''' Bind positional and named arguments to `func`. | |
e.g. | |
Input: | |
new_print = bind(print, '>', sep=' ', end='!\n') | |
Output: | |
new_print('Test') | |
> Test! | |
''' | |
def func_wrapper(*_args, **_kwargs): | |
return func(*args, *_args, **dict(kwargs, **_kwargs)) | |
return func_wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment