이것은 내가 알 수없는 단순한 오류가있는 것처럼 보입니다. C# WPF 응용 프로그램에서 IronPython을 사용하고 있고 사용자 정의 C# 클래스에서 함수를 실행하려고하면 다음 오류가 발생합니다. AttributeError: 'MyScriptingFunctions' object has no attribute 'Procedure'
.IronPython - "AttributeError : 객체에 속성이 없습니다."사용자 정의 클래스
내가 실행중인 python 스크립트는 매우 간단하고 두 줄이 있습니다.
private void btnRunScript_Click(object sender, RoutedEventArgs e)
{
MyScriptingFunctions scriptFuncs = new MyScriptingFunctions();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptRuntime runtime = engine.Runtime;
runtime.LoadAssembly(typeof(String).Assembly);
runtime.LoadAssembly(typeof(Uri).Assembly);
//Set Variable for the python script to use
scope.SetVariable("txt", fullReadResultsTextBox);
scope.SetVariable("MyFunc", scriptFuncs);
string code = this.scriptTextBox.Text;
try
{
ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
source.Execute(scope);
}
catch (Exception ex)
{
ExceptionOperations eo;
eo = engine.GetService<ExceptionOperations>();
string error = eo.FormatException(ex);
MessageBox.Show(error, "There was an Error");
return;
}
}
단순히 설정하고 :
여기class MyScriptingFunctions
{
public MyScriptingFunctions() {}
public void Procedure(int num)
{
Console.WriteLine("Executing procedure " + num);
}
}
가 어떻게 설정 IronPython의 엔진입니다 : 1 호선 오류가 줄에 2
txt.Text = "some text"
MyFunc.Procedure(5)
MyScriptingFunctions.cs 발생, 미세 실행 2 개의 변수 : System.Windows.Controls.TextBox
인 txt
및 내 사용자 정의 클래스 MyScriptingFunctions
의 대상인 MyFunc
입니다.
내가 뭘 잘못하고 왜 파이썬 스크립트가 TextBox 메서드를 올바르게 실행하고 사용자 정의 클래스의 메서드를 실행하지 않습니까?
그 트릭을했습니다. 매우 실망스러운 작은 오류. – McLovin
동일한 문제가 있었지만 수업을 공개로 생각하지 않았습니다. 이 문제에 얽매여있는 다른 사람들 : 수업은 공개 일 필요는 없지만 ** 방법은 회의 밖에서 볼 수있을 정도로 공개되어야합니다 **. 예를 들어, 파이썬이 인터페이스 메소드만을 호출하는 한, 공용 인터페이스를 구현하는 내부 클래스를 가질 수 있습니다. –
1 분 전에이 문제를 확인할 수 있습니다. 감사. –