1.安装python2.7(我的安装目录为C:\Python27)

2.在python2.7的安装目录中,找到Lib文件夹,复制整个文件夹到项目中

c# 调用python

c# 调用pythonc# 调用python

2.引用如下dll

c# 调用python

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);
         }    
    }
}        
View Code

相关文章:

  • 2021-11-05
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-10-07
  • 2021-06-21
  • 2021-06-18
相关资源
相似解决方案