#include <python2.6/Python.h>
main( ) {
PyObject * module;
PyObject * dict;
PyObject * obj;
long lval;
Py_Initialize( );
PyRun_SimpleString("abc = 2 * 3");
module = PyImport_AddModule("__main__");
dict = PyModule_GetDict(module);
obj = PyMapping_GetItemString(dict, "abc");
if (obj != NULL){
lval = PyInt_AsLong(obj);
} else {
printf("Object not found\n");
} /* if */
printf("Wert von abc: %d\n", (int) lval);
The variable abc of Python is read in as a C int variable.
Namespace in Python:
__main__