Last active
March 11, 2018 14:43
-
-
Save VEnis/4978004 to your computer and use it in GitHub Desktop.
Aggregating function arguments from inside function call
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
#http://kbyanc.blogspot.com/2007/07/python-aggregating-function-arguments.html | |
def arguments(): | |
"""Returns tuple containing dictionary of calling function's | |
named arguments and a list of calling function's unnamed | |
positional arguments. | |
""" | |
from inspect import getargvalues, stack | |
posname, kwname, args = getargvalues(stack()[1][0])[-3:] | |
posargs = args.pop(posname, []) | |
args.update(args.pop(kwname, [])) | |
return args, posargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment