An extension module written in C will have the following parts:
- A header segment, where you include all your external libraries and
Python.h
- An initialization segment, where you define the module name and the functions in your C module
- A method structure array to define all the functions in your module
- An implementation segment, where you define all the functions that you would like to expose
Header snippets are quite standard, just like a normal C module. We need to include the Python.h
header file to give our C code access to the internals of the C-API. This file is present in <path_to_python>/include
. We will be using an array object in our example code, hence we have included the numpy/arrayobject.h
header file as well. We don't need to specify the full path of the header file here as the path resolution is taken care of in setup.py
, which we will take a look at later:
/* Header Segment */ #include...