I need to run a Python script from c++, but I need also to pass it some variables. It can't be a function with parameters, because there are hundreds of variables, so the syntax would become too messy. I will post a simple example, analogue to my case. This is the Python script:
script.py
c = 10 * 5 + a
print(c)
And this is the calling code:
#include "Python.h"
int main()
{
Py_Initialize();
PyObject *pName = PyUnicode_FromString("script");
PyObject *pModule = PyImport_Import(pName);;
// Add something to set the cariable "a" in the script
Py_Finalize();
}
Could you help with the code to add to set the variable "a" in the script?
importtime? I think you wantPyRun_FileExFlagsinstead with a customglobalsdictionary.