I am trying to embed python in my C
code. So the objective is that I want to run a python code inside C
program, and when the python code finish running, it should return a integer value back to my C program.
In my python code "try.py", I specify return 10
at the end of the python file.
However, I tried the following, but the return value is always 0
. Why?
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{ int sys;
Py_Initialize();
PyObject* PyFileObject = PyFile_FromString("try.py", "r");
sys=PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), "try.py", 1);
Py_Finalize();
printf("\n\n the return value is %d\n\n",sys);
return 0;
}