I am trying to write a C# program that runs a python script. It,
looks something like this:
PyList pyargv = null;
PyObject sys = PythonEngine.ImportModule("sys");
pyargv = sys.GetAttr(new PyString("argv")) as PyList;
pyargv = new PyList();
foreach (string arg in argv)
string dir = System.IO.Path.GetDirectoryName(argv);
PyList path = new PyList(sys.GetAttr("path"));
PyObject pydir = new PyString(dir);
PyObject module =
So far, so good. At this point you may ask why I'm bothering and not
just using python.exe. Just trust me, that it's a bit specialized,
and I need to do a few other things. Namely, make some changes to the
global namespace. So, I added a function to PythonEngine to return
So that I can start adding some objects to it that the script can make use of.
Unfortunately, PyEval_GetGlobals returns 0. It does so in
PythonEngine.RunString as well. This seems kind of strange to me.
What am I doing wrong?