C# 调用 python脚本

2017/01/27 14:26
阅读数 377

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 收藏
0
分享
返回顶部
顶部