I have a built-in scripting engine in my C # application using IronPython 2. I create a Python runtime and add several classes to the global namespace so that the script can import them as modules.
However, one (rather simple) thing that I cannot understand is to send script arguments. I understand that I can just create a variable with a list of arguments, but there must be a proper way to do this. Also, by doing this in the correct "Python" way, I can compile scripts and use an automatic document creator called Sphinx. Therefore, the ultimate goal is to be able to use:
import sys sys.argv
In one of my scripts and get the arguments that the user specified (through the C # application).
Right now I'm calling a script using:
// set up iron python runtime engine _engine = Python.CreateEngine(); _runtime = _engine.Runtime; _scope = _engine.CreateScope(); // run script _script = _engine.CreateScriptSourceFromFile(_path); _script.Execute(_scope);
And I tried to find an API to add script arguments without any luck. I also tried adding them to the script path (_path in the example) with no luck. I tried with the file CreateScriptSourceFrom and CreateScriptSourceFromSting (which was a long shot anyway ...).
Am I trying to make this even possible?
source share