Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81876

Re: Python, C++ interaction

References <547EC9E2.8070502@perfect-kreim.de>
Date 2014-12-03 17:17 -0800
Subject Re: Python, C++ interaction
From Dan Stromberg <drsalists@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16542.1417655843.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Dec 3, 2014 at 12:29 AM, Michael Kreim <michael@perfect-kreim.de> wrote:
> Hi,

> I did some googleing on extending Python by C++ code but I did not find
> something that satisfies me. I gave SWIG a try, but several webpages
> disadvised me of using it. Also my small experiments did not work. Now, I
> read about ctypes. But as far as I understood it, I have to write a C
> wrapper for my C++ code and then a Python wrapper for my C code. That seems
> a little complicated.

> What are you using to wrap C++ classes for Python?
> Can you recommend swig? Should I give it another try?
> Did I misunderstood ctypes?
>
> Also later on in our code development we would like to pass python lambda
> functions to C++. So far I understood that this seems not to be possible. Do
> you have any ideas or hints on this topics?

You've already received some good suggestions.

I'll add that ctypes is a bit slow in CPython.

Also, you might want to try one or more of the following before
resorting to a less-productive language like C++:
1) writing in Cython+CPython (as opposed to wrapping C++ with Cython)
2) using numba+CPython (It's a pretty fast decorator - I've heard it's
faster than Cython)
3) shedskin (translates implicitly static Python to C++)
4) pypy (Python with a JIT - ignore RPython)

Here's a link I've been maintaining about ways of speeding up Python:
http://stromberg.dnsalias.org/~strombrg/speeding-python/

HTH

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python, C++ interaction Dan Stromberg <drsalists@gmail.com> - 2014-12-03 17:17 -0800

csiph-web