动态构建python扩展。直接从Python运行C++代码
cfl的Python项目详细描述
- 动态构建python扩展。
示例
fromcflyimportbuild_modulemymodule=build_module('mymodule',''' #define PY_SSIZE_T_CLEAN #include <Python.h> struct Foobar { PyObject_HEAD }; PyObject * meth_hello_world(PyObject * self) { return PyLong_FromLong(1234); } ''')print(mymodule.Foobar)print(mymodule.hello_world())
输出
<class'mymodule.Foobar'>1234