我正在编写调试器,我需要访问先前调用的框架
的局部变量例如,我有一个这样的代码:
def foo():
...
result = bar(args) # bar is some function
locals_of_bar = ...#get the locals() dict of the frame in which `bar` was called
编辑:我已更新问题以便更清晰。
答案 0 :(得分:-1)
你能做的最好的事情是:
def foo():
print bar_locals()
def bar_locals():
a=1
b=2
return locals()
另外:
您可以执行以下操作:
locals_of_methods = {}
def bar(): #执行功能 全球locals_of_methods locals_of_methods ['杆':当地人()] #return
执行bar()
后,您将拥有locals_of_methods