globals()函数会以字典类型返回当前位置的全部全局变量。
x="test"
y="validation"
print(globals())
输出:
{ '__name__': '__main__',
'__doc__': None,
'__package__': None,
'__loader__':<_frozen_importlib_external.SourceFileLoader object at 0x0000022B1AAD6630>,
'__spec__': None,
'__annotations__': {},
'__builtins__': <module 'builtins' (built-in)>,
'__file__': 'D:/github_code/fastslow/SlowFast/test.py',
'__cached__': None,
'x': 'test',
'y': 'validation'
}
参考:
https://www.runoob.com/python/python-func-globals.html