There's a bit of setup in the beginning to create a dict and add it to the namespace, and also I copied some of default.py's code for setting up the sys.path variable the same way. HandleStdO is a static function for redirecting print statement and such to my app.
Code:
CSPyInterpreter* interpreter = CSPyInterpreter::NewInterpreterL();
interpreter->iStdO = (HandleStdO);
char* argv[1];
int argc = 0;
argv[0] = (char*)iFile.PtrZ();
argc++;
PyEval_RestoreThread(PYTHON_TLS->thread_state);
PyObject *row = PyDict_New();
TInt size = names->MdcaCount();
for (int ii = 0; ii < size; ii++)
{
TPtrC ptr = names->MdcaPoint(ii);
PyObject *key = Py_BuildValue("u#", ptr.Ptr(), ptr.Length());
ptr.Set(values->MdcaPoint(ii));
PyObject *value = Py_BuildValue("u#", ptr.Ptr(), ptr.Length());
PyDict_SetItem(row, key, value);
Py_DECREF(key);
Py_DECREF(value);
}
PyObject *builtin = PyImport_ImportModule("__builtin__");
PyObject *builtin_dict = PyModule_GetDict(builtin);
Py_DECREF(builtin);
PyDict_SetItemString(builtin_dict, "current_row", row);
Py_DECREF(row);
//PyRun_SimpleString("print current_row");
PyRun_SimpleString("import sys, os");
PyRun_SimpleString("for path in ('c:\\python\\lib','e:\\python\\lib'):\n if os.path.exists(path):\n sys.path.append(path)\n");
//PyRun_SimpleString("print sys.path");
PyEval_SaveThread();
TInt err = interpreter->RunScript(argc, argv);
if (err != KErrNone)
{
interpreter->PrintError();
}
delete interpreter;