1.安装python2.7(我的安装目录为C:\Python27)
2.在python2.7的安装目录中,找到Lib文件夹,复制整个文件夹到项目中
2.引用如下dll
3.写如下代码
using Hm.Common.InitPythonRuntime; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace { public class PythonUtil { private InitRuntime pythonRuntime=null; //python文件位置 private readonly string PythonFilePath="....a.py" private readonly string DllPath=AppDomain.BaseDirectory+"Hammer.Common.dll"; public bool AnalysisEndStr(string targetStr) { if(pythonRuntime==null) pythonRuntime=new InitRuntime(); pythonRuntime.loadPythonFile(DllPath,PythonFilePath); dynamic obj=pythonRuntime.GetDPython(); return obj.callPthon("IsEndStr",targetStr); } } }