首先下载最新的IrorPython(点击打开链接),目前最新的是2.7.8。安装。
引用安装路径下的DLL(C:\Program Files\IronPython 2.7)
新建一个Winfrom程序调用写好的Python代码
ScriptEngine pyEngine = Python.CreateEngine();//创建Python解释器对象
ScriptSource source = pyEngine.CreateScriptSourceFromFile(@"E:\TestPythonProjects\PythonApplication1\PythonApplication2\AAnalyze27.py");
ScriptScope scope = pyEngine.CreateScope();
try
{
//设置参数
scope.SetVariable("arg1", tbAddress.Text);
}
catch (Exception)
{
MessageBox.Show("输入有误。");
}
source.Execute(scope);
//获取结果【在python中为全局变量值】
dynamic nam