C++ and Python

hg hg at nospam.org
Fri Mar 9 22:16:43 CET 2007

Gabriel Genellina wrote:

> En Fri, 09 Mar 2007 05:28:54 -0300, hg <hg at nospam.org> escribió:
>> Mandus wrote:
>>> 8 Mar 2007 22:04:48 -0800 skrev bressert at gmail.com:
>>>> I'm considering about generating some Python Bindings for C++
>>>> libraries. What are considered the best tools for doing something like
>>>> this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
>>> We are doing this quite extensively at work, and have found that in the
>>> long run SWIG is the best solution. OMMV, but if you ask me, the answer
>>> is SWIG.
>> Why do you think it is better than ctypes ?
> I won't say SWIG is better than anything, but how would you use ctypes to
> create an instance of a class with several levels of inheritance, and then
> invoke a virtual method?
> You have to mangle all the names (not too bad, can be done in Python
> following the rules) but you also need to find the right function pointer
> in the virtual method table; and that can't be done without processing the
> source code (at least the .h) in order to know the layout and ordering of
> the methods.
> Let alone inline functions, templates and #define macros.
> --
> Gabriel Genellina

I'm not very familiar with the technology as I just have had to modify an
extension here and there.

I guess my question is off topic as a C++ dll / shared lib is not my main
target but rather C: I need to integrate a printer driver and and would
like if possible to avoid all of the .h stuff involved with SWIG (I am not
being sarcastic): if I can setup my prototypes directly in python, why go
through an extra layer ?

Aren't ctypes better suited to such an application ?


More information about the Python-list mailing list