Skip to content

Instantly share code, notes, and snippets.

@VEnis
Last active March 11, 2018 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save VEnis/4978004 to your computer and use it in GitHub Desktop.
Save VEnis/4978004 to your computer and use it in GitHub Desktop.
Aggregating function arguments from inside function call
#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