using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WpfUsingPythonDemo
{
public class UsingPython
{
private ScriptRuntime pyRuntime = null;
private dynamic obj = null;
public UsingPython()
{
string serverpath = AppDomain.CurrentDomain.BaseDirectory + "frs_main.py";//所引用python路径
pyRuntime = Python.CreateRuntime();
ScriptEngine Engine = pyRuntime.GetEngine("python");
ScriptScope pyScope = Engine.CreateScope(); //Python.ImportModule(Engine, "random");
obj = Engine.ExecuteFile(serverpath, pyScope);
}
public bool ExcutePython()
{
try
{
if (null != obj)
{
obj.frs_init();//调用frs_main.py中的方法
}
else
{
return false;
}
return true;
}
catch(Exception ex)
{
throw ex;
}
}
}
}