Extending Python with C or C++

Ryan heniser at yahoo.com
Mon Jan 5 19:27:34 EST 2009


On Jan 5, 2:37 pm, Terry Reedy <tjre... at udel.edu> wrote:
> Ryan wrote:
> > I've been using Python for many years now. It's a wonderful language
> > that I enjoy using everyday. I'm now interested in getting to know
> > more about the guts
>
> The 'guts' of Python the language include the object model, namespaces
> (including modules), and the statement and infix-expression syntax.
>
> > (C/C++) and extending it.
>
> Now you are asking about CPython, the leading computer implementation.
>
> > But, extending python still seems like a black art to me.
>
>  > Is there anymore docs or info on
>
> > extending it besides the standard sparse ones (http://www.python.org/
> > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a
> > class available?
>
> If you want to connect CPython to Python-oblivious code written in C,
> Swig (with C code) and Ctypes (with Python code) are the main choices.
> If you want to write new Python-aware (and specific) code, you can use
> the CPython C-API functions.  Extensions in C are written as importable
> modules.  The interface for such is not difficult; existing examples
> should be a good guide.
>
>  > How can I learn more about the guts of python?
>
> The 'guts' of an implementation follow from the 'guts' of the language.
>   There must be a syntax parser and compiler to internal form,
> evaluation loop, and implemenations of built-in constants, functions,
> classes, and modules.  CPython's source tree begins ashttp://svn.python.org/view/
> You might actually want to start athttp://svn.python.org/view/python/trunk/
> Note: if you click a filename, such as 'setup.py', you get the entire
> revision history with checkin messages.
> If you click the displayed revision number, such as '67978', you get the
> latest checkin message and the current version of the file.
>
> > How would one go about following an interest in contributing to the
> > development of python.
>
> Readhttp://python.org/dev/
> and start following the pydev list, mirrored to gmane.comp.python.devel
> at news.gmane.org.
>
> Terry Jan Reedy

Thanks Terry! This clarifies many of the concepts that I want to get
started to dive deeper into CPython.

1. The abstract Python Language (not specific to any implementation)
2. The CPython implementation (http://svn.python.org/view/python/
trunk/)
3. Extending CPython by connecting it to Python-oblivious code written
in C with Ctypes (Ralf's suggestion is good for this)
4. Extending CPython by connecting it to Python-aware (and specific)
code using the CPython C-API functions (http://docs.python.org/c-api/)



More information about the Python-list mailing list