It is quite easy to add non-standard built-in modules to Python, if
you know how to program in C. A built-in module known to the Python
programmer as foo
is generally implemented by a file called
`foomodule.c
'. All but the two most essential standard built-in
modules also adhere to this convention, and in fact some of them form
excellent examples of how to create an extension.
Extension modules can do two things that can't be done directly in
Python: they can implement new data types (which are different from
classes by the way), and they can make system calls or call C library
functions. Since the latter is usually the most important reason for
adding an extension, I'll concentrate on adding `wrappers' around C
library functions; the concrete example uses the wrapper for
system()
in module posix
, found in (of course) the file
`Modules/posixmodule.c
'.
Note: unless otherwise mentioned, all file references in this
document are relative to the toplevel directory of the Python
distribution - i.e. the directory that contains the `configure
'
script.
The compilation of an extension module depends on your system setup and the intended use of the module; details are given in a later section.