C# 調用 python腳本

C# 調用 python腳本

pythonpython

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

csharpmarkdown

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();
        }
    }
}
相關文章
相關標籤/搜索