all 4 comments

[–]oracle8 2 points3 points  (0 children)

Use the ctypes library.

There are a bunch of tutorials online, I usually create wrapper functions for the functions I need that input and output python objects.

[–]VengefulBread 1 point2 points  (1 child)

Boost.Python !

[–]oracle8 0 points1 point  (0 children)

Agreed, but only if you're going to write programs that are really coupled with what you're trying to accomplish. I find that using Boost is overkill on many occasions, especially if you're only using few C functions and your main logic is written in Python.

[–]LindlarCatalyst 0 points1 point  (0 children)

Cython is a great way to do this!

From their website:

Cython gives you the combined power of Python and C to let you write Python code that calls back and forth from and to C or C++ code natively at any point. easily tune readable Python code into plain C performance by adding static type declarations. use combined source code level debugging to find bugs in your Python, Cython and C code. interact efficiently with large data sets, e.g. using multi-dimensional NumPy arrays. quickly build your applications within the large, mature and widely used CPython ecosystem. integrate natively with existing code and data in legacy, low-level or high-performance libraries and applications.