Python or C or Python+C ?

We present a discussion on the use of the C and the Python languages and the use of Python calling a C library. Some arguments are general while others arise from the specific application of modifying a .csv (text) file.

Calling C from Python

Whatever the reason you would like to call C functions from Python, one approach is presented here and consists in creating a C dynamic library, compiled as a .so module and accessing the library thanks to the ctypes package of Python. Explanations are given step by step and stand for a Linux environment (tested with Ubuntu20.04).

Creating a dynamic library in C

C libraries are handy for distribution of programming work or for structuring a large development into units. In the specific case of Python programming, a C dynamic library can be a solution for a missing Python equivalent or if performance in execution time is a concern. We explain hereunder with an example the steps necessary to write a dynamic (shared) C library in Linux (tested on Ubuntu20.04). Another blog describes how to call a C dynamic library from Python ([https://cylab.be/blog/235/calling-c-from-python]).

This website uses cookies. More information about the use of cookies is available in the cookies policy.