Reputation: 2181
I have an C code, and there is some simple file manipulation I would need to do at the beginning for initialization purposes, that would be straightforward with Python. I was wondering if there is a way to do that with calling python from C. I am familiar with calling C from Python, but for doing the opposite I have read that Cython could do but I am very confused on how.
The python code has to take in input some strings, make some files manipulation and return some doubles and arrays.
Upvotes: 1
Views: 171
Reputation: 428
To call Python from C, it is quite simple. First you need to install the python-dev packages to get access to the Python.h file. then you have access to the python api. Here is the reference for the api: https://docs.python.org/2/c-api/intro.html. specifically pay attention to the Embedding Python section. The basic process is to call Py_Initialize() execute your python code and then call Py_Finalize()
Upvotes: 3