Python and C++

Gerhard Häring gerhard.nospam at
Wed Jul 18 01:38:01 CEST 2001

On Tue, 17 Jul 2001 18:24:59 -0300, Tatiana Evers wrote:
>I'm a new python user. I would like to know how can I extend Python ? I read
>documents in, but I didn't found anything about class in C++.

There is no standardized C++ API for Python, only a C API :-( There are several
tools that help wrapping a C++ class for Python, however. The one I like most
is the Boost.Python library (
Exposing a C++ class to Python is as easy as it can get with this one.

I can imagine though, that building the library can be a bit problematic. But
they have a mailing list where you can ask for help. (if you use Linux, I can
send you an RPM I have built; I have also built the library on Windows with the
GNU compilers).

>Anyone knows something about it ? One example or site or tutorial?

The Boost.Python library contains docs and examples that show its features. You
can even throw exceptions in C++ and catch them in Python. Just to wet your
appetite ...

Perhaps it's also not a bad idea to look into how to do it the old-fashioned
style in C. The standard Python documentation has a chapter "Extending and
Embedding" that briefly tells how this works. For source examples, you can look
into the Python sourcecode itself (the Modules directory).

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:              public key at homepage
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y: x+y, [chr(ord(x)^42) for x in list('zS^BED\nX_FOY\x0b')])

More information about the Python-list mailing list