views:

151

answers:

1
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 the python execution currently is (the function surrounding line frame.f_lineno).

+1  A: 

You can access frame.f_locals which should let you get/set all of the variables.

Dino Viehland
please step thru the code above, ... frame.f_locals does NOT contain the locals
ulrichb
If I change OnTraceback to return it's self I see locals inside of the square functions - although the globals do seem to be missing.
Dino Viehland