calling Python from C

2019-04-15 23:03发布

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.

标签: python c cython
1条回答
相关推荐>>
2楼-- · 2019-04-15 23:39

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()

查看更多
登录 后发表回答