From: carlos c. <hap...@ho...> - 2006-12-01 18:54:45
|
I am thinking of using PyCXX principally for embedding Python. Here is some basic code for embedding that I intend to use: **************************************************************** #include <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc, *pValue; if (argc < 3) { printf("Usage: exe_name python_source function_name\n"); return 1; } // Initialize the Python Interpreter Py_Initialize(); // Build the name object pName = PyString_FromString(argv[1]); // Load the module object pModule = PyImport_Import(pName); // pDict is a borrowed reference pDict = PyModule_GetDict(pModule); // pFunc is also a borrowed reference pFunc = PyDict_GetItemString(pDict, argv[2]); if (PyCallable_Check(pFunc)) { PyObject_CallObject(pFunc, NULL); } else { PyErr_Print(); } // Clean up Py_DECREF(pModule); Py_DECREF(pName); // Finish the Python Interpreter Py_Finalize(); return 0; } ********************** I assume the above will work. Is there a more PyCXX way of doing this? Lastly, I need to have callbacks into C++ code from Python. The Callable interface is documented, but samples. Can someone please post examples of how to use it? _________________________________________________________________ Off to school, going on a trip, or moving? Windows Live (MSN) Messenger lets you stay in touch with friends and family wherever you go. Click here to find out how to sign up! http://www.live.com/?mkt=en-ca |