IronPython: how to access tracing local variables

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;
}

      

Let me repeat: I want to get the local variables of the function where python is currently executing (the function surrounding the string frame.f_lineno

).

+2


source to share


1 answer


You can access the .f_locals frame, which should allow you to get / set all the variables.



+1


source







All Articles