Created
July 22, 2015 10:51
-
-
Save ficapy/f5e772812fcfe228db46 to your computer and use it in GitHub Desktop.
返回函数参数名和传入参数值的dict表
This file contains 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 foo(f, b): | |
c = 3 | |
# 以下写法错误,locals是会变化的即使使用list(locals())依然无法得到正确的结果 | |
# [locals.get(i) for i in locals()] | |
# 以下2、3通用 | |
frame = inspect.currentframe() | |
args, _, _, value = inspect.getargvalues(frame) | |
print({i:value.get(i) for i in args}) | |
foo(1, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment