Python Binding

Nick Craig-Wood nick at craig-wood.com
Sun May 6 14:30:04 EDT 2007


Georg Grabler <ggrabler at gmail.com> 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?

Sounds like a job for ctypes which is bundled with py 2.5.

  http://docs.python.org/lib/module-ctypes.html

It is great for access C libraries (assuming you have a shared library
(.so or .dll).

You'll end up writing python code rather than C code which you'll
enjoy!

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list