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


Groups > comp.lang.python > #81849 > unrolled thread

Re: Python, C++ interaction

Started bySturla Molden <sturla.molden@gmail.com>
First post2014-12-03 10:15 +0000
Last post2014-12-03 10:15 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python, C++ interaction Sturla Molden <sturla.molden@gmail.com> - 2014-12-03 10:15 +0000

#81849 — Re: Python, C++ interaction

FromSturla Molden <sturla.molden@gmail.com>
Date2014-12-03 10:15 +0000
SubjectRe: Python, C++ interaction
Message-ID<mailman.16524.1417601758.18130.python-list@python.org>
Cython is nearly always the answer to scientific computing in Python,
including wrapping C++.

Sturla


Michael Kreim <michael@perfect-kreim.de> wrote:
> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web