C# 调用 python脚本

来源:互联网 发布:还原数据库是不是很慢 编辑:程序博客网 时间:2024/05/12 04:17

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();        }    }}
0 0