您的位置:首页 > 编程语言 > Python开发

c# 调用python

2016-07-29 09:37 260 查看
1.安装python2.7(我的安装目录为C:\Python27)

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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: