久々に C# から Iron Python を呼び出そうとして変わってたのでメモ。
1.1.2.0
using (PythonEngine engine = new IronPython.Hosting.PythonEngine()) // Python Engine 生成 { engine.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly()); // Engine に必要なアセンブリを読み込ます engine.ExecuteFile(string.Format("{0}/hoge.py", ScriptFilePath)); // py ファイルを実行 ret = engine.EvaluateAs<T>("createdInstance"); // 実行後に、createInstance という名前の値を取得 }2.0.0.0
var engine = IronPython.Hosting.Python.CreateEngine(AppDomain.CurrentDomain); // Python Engine 生成 var scope = engine.CreateScope(); // 実行スコープ?を生成 engine.ExecuteFile(string.Format("{0}/hoge.py", ScriptFilePath), scope); // py ファイルを実行 ret = scope.GetVariable<T>("createInstance"); // 実行後に、createInstance という名前の値を取得
多分 DLR を使う様になったからじゃないかと想像。2.0 の Engine って Microsoft.Scripting.Hosting.ScriptEngine 型だし。