IronPython使用

C#:

class Program
{
    static void Main(string[] args)
    {
        ScriptEngine engine = Python.CreateEngine();
        ScriptScope scope = engine.CreateScope();
        var sourceCode = engine.CreateScriptSourceFromFile("Main.py");
        sourceCode.ExecuteProgram();
        Console.WriteLine("Executed");
        Console.Read();
    }
}

Python:(Main.py)

def Foo():
    print "Hellow world"    

if __name__ == '__main__':
    Foo()

然后把Main.py的复制到输出目录配制成"始终复制",然后运行后打印结果:

原文地址:https://www.cnblogs.com/hont/p/5174055.html