Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
返回函数参数名和传入参数值的dict表
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
You can’t perform that action at this time.