C#开发中IronPython的使用

目前的最新版本是:3.4.1

安装

Install-Package IronPython

如果需要使用标准库,则进行下面的安装

Install-Package IronPython.StdLib

在C#程序中执行Python代码

示例代码:

var eng = IronPython.Hosting.Python.CreateEngine();
var scope = eng.CreateScope();
eng.Execute(@"
def greetings(name):
    return 'Hello ' + name.title() + '!'
", scope);
dynamic greetings = scope.GetVariable("greetings");
System.Console.WriteLine(greetings("world"));

参考网址

https://ironpython.net/

https://github.com/IronLanguages/ironpython3

posted @ 2023-07-13 15:47  wzwyc  阅读(198)  评论(0编辑  收藏  举报