Easiest way to access C module in Python
Christian Gollwitzer
auriocus at gmx.de
Tue Nov 7 01:46:58 EST 2017
Am 07.11.17 um 02:59 schrieb Grant Edwards:
> On 2017-11-06, John Pote <johnpote at jptechnical.co.uk> wrote:
>
>> I have successfully used Python to perform unit and integration tests in
>> the past and I'd like to do the same for some C modules I'm working with
>> at work. There seem to be a number of ways of doing this but being busy
>> at work and home I looking for the approach with the least learning curve.
>
> When I want to test C modules (usually destined for an embedded
> system) using a Python framework, I use ctypes.
>
> https://docs.python.org/3/library/ctypes.html
>
Another possibility is SWIG
http://www.swig.org/
When you already have a C header file, SWIG creates a Python module out
of it. In many cases this is sufficient to get a runnable interface, but
sometimes you need to add additional functions (like initialisation
functions) to your module to make it usable from Python.
Christian
More information about the Python-list
mailing list