Embedding python question: PyRun_String only returns None no
Gordon McMillan
gmcm at hypernet.com
Tue Apr 6 23:12:31 EDT 1999
Dave Kuhlman replies to a query about PyRun_SimpleString...
> When you embed Python in an application, the application often
> exposes functions that are callable from Python scripts. You could
> provide a function named setReturnValue(value), which when called,
> passed a Python object (the value). The script calls this function,
> and then, when it exits, the embedding application (the caller of
> PyRun_String or PyRun_SimpleString) uses the Python value saved by
> this function.
With all the error checking and some app specific logic removed,
here's some code that loads a module and calls a specific function in
that module:
module = PyImport_ImportModule("mymodule");
moduledict = PyModule_GetDict(module);
func = PyDict_GetItemString(moduledict, "CheckMenu");
args = Py_BuildValue("(ss)", "spam", "eggs");
retval = PyEval_CallObjectWithKeywords(func, args, (PyObject
*)NULL)
Py_XINCREF(retval);
rc = PyArg_Parse(retval, "s", &str);
Py_XDECREF(retval);
Py_XDECREF(module);
- Gordon
More information about the Python-list
mailing list