Created
January 7, 2017 21:11
-
-
Save iuridiniz/0fc3e64536523ec678533722a6ebb00e to your computer and use it in GitHub Desktop.
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
from __future__ import print_function | |
import sys | |
import inspect | |
def func(a, b, c, *args, **kwargs): | |
frame = inspect.currentframe() | |
args_names, _, _, locals_ = inspect.getargvalues(frame) | |
args = [locals_[i] for i in args_names] | |
kwargs = dict(zip(args_names, args)) | |
print ("kwargs: %r" %kwargs) | |
print ("args: %r" %args) | |
def dumpargs(): | |
frame = sys._getframe(1) | |
args_names, _, _, locals_ = inspect.getargvalues(frame) | |
args = [locals_[i] for i in args_names] | |
kwargs = dict(zip(args_names, args)) | |
return args, kwargs | |
def outra(a, b, c, d=1): | |
args, kwargs = dumpargs() | |
print("kwargs: %r" %kwargs) | |
print("args: %r" %args) | |
if __name__ == "__main__": | |
outra(1,2,3,4) | |
func(1,2,3, lol='1') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment