I'm trying to include a Python module in my C program and thought I would write a very simple Hello World Python script to test it out. Unfortunately this code does not seem to work. There also seems to be very little in the way of documentation on the specifics. I have read the page regarding this subject on python.org but have not found any sufficient information regarding the problem.
Here is the C code:
PyObject *module, *dict, *func, *value;
Py_Initialize();
module = PyImport_ImportModule("logic");
dict = PyModule_GetDict(module);
func = PyDict_GetItemString(dict, "logic");
value = PyObject_CallFunction(func, "HW", "");
Py_DECREF(module);
Py_DECREF(dict);
Py_DECREF(func);
Py_DECREF(value);
Py_Finalize();
And the Python code:
def HW():
print 'Hello World!'