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

C# 调用 python脚本

2017-01-27 00:00 155 查看

C# 调用 python脚本

python

def welcome(name):
return "Hello '" + name + "' from IronPython"

csharp

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace PythonSample {
class Program {
static void Main(string[] args)
{
Console.WriteLine("Loading helloworld.py...");

ScriptRuntime py = Python.CreateRuntime();
dynamic helloworld = py.UseFile("helloworld.py");

Console.WriteLine("helloworld.py loaded!");

for (int i = 0; i < 1000; i++)
{
Console.WriteLine(helloworld.welcome("Employee #{0}"), i);
}
Console.ReadLine();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: