2009-10-09 8 views
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 : 추적 다시 지역 변수에 액세스하는 방법

답변

1

모든 변수를 가져 오거나 설정할 수있는 frame.f_locals에 액세스 할 수 있습니다.

+0

위의 코드를 통해 단계를 밟으십시오. frame.f_locals에 지역 번호가 포함되어 있지 않습니다. – ulrichb

+0

OnTraceback을 자체로 되돌리려면 지역 함수가 내부에 있음을 확인하십시오. 전역 변수는 누락 된 것 같습니다. –

관련 문제