[Tutor] c++ on python

Russel Winder russel at winder.org.uk
Thu Mar 13 17:29:57 CET 2014


On Thu, 2014-03-13 at 16:57 +0100, Stefan Behnel wrote:
[…]
> The thing is: if you have to write your own wrapper anyway (trivial or
> not), then why not write it in Cython right away and avoid the intermediate
> plain C level?

If the task is two write an adapter (aka wrapper) then perhaps use SWIG
whcih is easier for this task than writing Cython code.

> It's usually much nicer to work with object oriented code on both sides
> (assuming you understand the languages on both sides), than to try to
> squeeze them through a C-ish API bottleneck in the middle.

It could be that "object oriented" is a red herring. Without details (*)
of what it is about the C++ code that is the connection between Python
and C++, it is difficult to generalize.

ctypes can be a real pain when trying to call C++ from Python using
argument values that are not primitive types. CFFI solves (currently
much, soon most) of this problem by addressing the adapter between
Python and C++ in a different way to that employed by ctypes. In both
cases, both are a lot easier than writing Cython code. 


(*) I may have just missed this detail in which case apologies.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/tutor/attachments/20140313/887dc563/attachment.sig>


More information about the Tutor mailing list