0

Using the python script engine set up in C# using IronPython, is there a way to retrieve the current executing function from the python code?

E. g. in my code, the setup python script engine is stored in variable pse. Is there a call similar to pse.GetVariables() that returns the current executing python function?

I would like to be able to pull this information so I could use it in a check within a test, for example.

1 Answer 1

1

You can use the trace functionality for that. Set a trace callback that will be called for each line of the executing script. From that callback, you can get the function name that is currently executing.

pse.SetTrace(IronPythonTraceCallbaback);

And the callback definition:

static TracebackDelegate IronPythonTraceBack(TraceBackFrame frame, string result, object payload)
{
    if (frame != null && frame.f_code != null)
    {
         // Here you can access the executing function information
         FunctionCode functionCode = frame.f_code;
         string functionName = frame.f_code.co_name;
    }

    return IronPythonTraceBack;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.