How do I run a Python script from C#?

后端 未结 8 1849
猫巷女王i
猫巷女王i 2020-11-22 02:47

This sort of question has been asked before in varying degrees, but I feel it has not been answered in a concise way and so I ask it again.

I want to run a script in

8条回答
  •  不要未来只要你来
    2020-11-22 03:03

    If you're willing to use IronPython, you can execute scripts directly in C#:

    using IronPython.Hosting;
    using Microsoft.Scripting.Hosting;
    
    private static void doPython()
    {
        ScriptEngine engine = Python.CreateEngine();
        engine.ExecuteFile(@"test.py");
    }
    

    Get IronPython here.

提交回复
热议问题