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


Groups > comp.lang.python > #81847

Python, C++ interaction

Date 2014-12-03 09:29 +0100
From Michael Kreim <michael@perfect-kreim.de>
Subject Python, C++ interaction
Newsgroups comp.lang.python
Message-ID <mailman.16522.1417595824.18130.python-list@python.org> (permalink)

Show all headers | View raw


Hi,

we are working on a small scientific program that helps us in developing 
and testing of new numerical methods for a certain type of biochemical 
problems. I spare you the math ;-)

We code our new methods in Python and compare them with the existing 
methods. Unfortunately, these existing methods are quite slow and need a 
lot of runtime. Therefor we implemented them in C++.

Now, we like to combine these two approaches. So we can develop a new 
method in Python and compare it easily with the results from the C++ 
functions.

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.

My C++ code is structured as a class that contains several variables and 
functions. Then everything is compiled as a shared library. I can write 
things like:

MyClass.initialvalue = 5;
MyClass.timestep = 0.1;
...
MyClass.solve();

I would like to keep this structure in python, but if I understand 
ctypes correctly I would loose the class approach.

So after the long writeup I come to my questions:

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?

Thank you very much.

Cheers,

Michael

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


Thread

Python, C++ interaction Michael Kreim <michael@perfect-kreim.de> - 2014-12-03 09:29 +0100
  Re: Python, C++ interaction Christian Gollwitzer <auriocus@gmx.de> - 2014-12-04 09:49 +0100

csiph-web