2
private ScriptEngine pe;
private ScriptScope scope;
private void button1_Click(object sender, EventArgs e)
{
pe = Python.CreateEngine();
scope = pe.CreateScope();
pe.Runtime.SetTrace(OnTraceback);
pe.Execute(@"
def square(x):
s = x*x
return s
a = square(2) + (3)
print ""hello world "" + str(a)
", scope);
}
private TracebackDelegate OnTraceback(TraceBackFrame frame, string result, object payload)
{
//How can I access the local variables of the current function?
return OnTraceback;
}
让我再说一遍:我想要得到的功能,其中蟒蛇执行目前的局部变量(函数周围线frame.f_lineno
)。IronPython的:如何访问追溯局部变量
请逐步通过上面的代码,... frame.f_locals不包含当地人 – ulrichb 2009-10-10 00:02:51
如果我改变OnTraceback返回它的自我,我看到方形函数内的本地人 - 尽管全局似乎没有。 – 2009-10-10 00:54:22