Python, C++ interaction
Dan Stromberg
drsalists at gmail.com
Wed Dec 3 20:17:15 EST 2014
On Wed, Dec 3, 2014 at 12:29 AM, Michael Kreim <michael at 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
More information about the Python-list
mailing list