zoukankan      html  css  js  c++  java
  • c# 调用python

    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);
             }    
        }
    }        
    View Code
  • 相关阅读:
    C#第一节课作业,HelloWorld
    C# 第四次作业
    前端浅入汇总
    对象——浅识
    CSS圆角
    javascript中工厂模式
    C#中抽象类
    ASP.NET新知识
    ReSharper快捷键
    JS调用webservice
  • 原文地址:https://www.cnblogs.com/mrxiaohe/p/5717149.html
Copyright © 2011-2022 走看看