Python Binding

Stefan Sonnenberg-Carstens stefan.sonnenberg at pythonmeister.com
Sun May 6 02:52:43 EDT 2007


Stefan Behnel schrieb:
> Georg Grabler wrote:
>   
>> There's a C library which i'd like to have python bindings for. I havn't
>> known anything before about how to write python bindings for a C library.
>>
>> I succeeded now by using distutils to write the first bindings for functions
>> and similar.
>>
>> Now, it seems as something is blocking my brain. For the library, i
>> need "custom" types, so types defined in this library (structures),
>> including pointers and similar.
>>
>> I've been thinking about what i will need to represent this lists in python.
>> I thought about creating an external python object, providing "information"
>> i get from the list in C structures which can be converted.
>>
>> Basically, it are list of packages, which have several attributes (next,
>> prev, etc). But i don't know how to supply a proper list from the binding /
>> object written in C.
>>
>> Any suggestions or hints about this?
>>     
>
> Use Pyrex. It's a Python-like language that was designed to write extension
> modules in C and it's great for writing wrappers.
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
>
> An example wrapper is described here:
>
> http://ldots.org/pyrex-guide/
>
> Hope it helps,
> Stefan
>   
Hi,
use SWIG.
It is a no-brainer for simple libs. wxPython relies heavily on it.
I worked with some times and it is really straightforward.
See this: http://www.swig.org/Doc1.1/HTML/Python.html
Cheers,
Stefan



More information about the Python-list mailing list