Pat*_*win 9 python error-handling
我正在尝试收集有关崩溃的信息,我无法弄清楚如何获得崩溃函数中使用的全局变量.
import inspect
fun = 222
other = "junk"
def test():
global fun
harold = 888 + fun
try:
harold/0
except:
frames = inspect.trace()
print "Local variables:"
print frames[0][0].f_locals
print "All global variables, not what I want!"
print frames[0][0].f_globals
test()
Run Code Online (Sandbox Code Playgroud)
test()只使用"fun",但f_globals给出了所有可用的全局变量.有没有办法获得这个函数正在使用的全局变量?