Py学习  »  Python

在.net中调用python函数

Barsa Swain • 4 年前 • 150 次点击  

我有Visual Studio 2013,我的主窗体是用C#编写的。 我有一个python(3.7)脚本,有很多函数(使用类似Pandas、Numpy等库)

i、 e.对于来自.net UI的特定事件,应该调用python脚本并将该值作为参数从python返回到.net,反之亦然

  1. 铁蟒

.Net代码:

using Microsoft.Scripting.Hosting;

using IronPython.Hosting;

using IronPython.Runtime.Types;

using IronPython.Modules;


ScriptEngine py = IronPython.Hosting.Python.CreateEngine();

ScriptScope scope = py.ExecuteFile("Square.py");

dynamic Excel1 = scope.GetVariable("Excel")();

Excel1.ReadExcel("C:\\filePath\\abc.xlsx");

Python Script:


class Excel:    

    def ReadExcel(self, Path):

         import pandas as pd

         df = pd.read_excel (Path)

         print (df)  

         return df

附加信息:没有名为pandas的模块

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56728
 
150 次点击