Skip to content

Instantly share code, notes, and snippets.

@rcj4747
Created April 19, 2019 13:25
Show Gist options
  • Save rcj4747/0b2cefa65f4e44cf2e8a3d2a1892ff98 to your computer and use it in GitHub Desktop.
Save rcj4747/0b2cefa65f4e44cf2e8a3d2a1892ff98 to your computer and use it in GitHub Desktop.
python snippet to print a callers function name and arguments
import inspect
def print_args():
'''Print the callers function name along with argument values'''
# TODO: print * and ** args
frame, _, _, name, _, _ = inspect.getouterframes(inspect.currentframe())[1]
args, _, _, values = inspect.getargvalues(frame)
print("%s: %s)" % (name, ["%s=%s" % (i, values[i]) for i in args]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment