Script arguments and Embedded IronPython

后端 未结 2 900
情书的邮戳
情书的邮戳 2020-12-06 20:40

I have an embedded scripting engine in my C# application that uses IronPython 2. I create the Python runtime and add a few classes to the global namespace so that the script

2条回答
  •  春和景丽
    2020-12-06 21:08

    When you create the engine, you can add an "Arguments" option the contains your arguments:

    IDictionary options = new Dictionary();
    options["Arguments"] = new [] { "foo", "bar" };
    _engine = Python.CreateEngine(options);
    

    Now sys.argv will contain ["foo", "bar"].

    You can set options["Arguments"] to anything that implements ICollection.

提交回复
热议问题