Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; ';-)': 0.03; 'subject:Python': 0.06; 'variables': 0.07; 'wrapper': 0.09; 'python': 0.11; 'approaches.': 0.16; 'c++.': 0.16; 'ctypes.': 0.16; 'experiments': 0.16; 'lambda': 0.16; 'runtime.': 0.16; 'try?': 0.16; 'code.': 0.18; 'numerical': 0.19; 'later': 0.20; 'seems': 0.21; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'questions:': 0.24; 'math': 0.24; 'cheers,': 0.24; 'compare': 0.26; 'compiled': 0.26; 'pass': 0.26; 'certain': 0.27; 'developing': 0.27; 'testing': 0.29; 'michael': 0.29; 'work.': 0.31; 'code': 0.31; 'ctypes': 0.31; 'extending': 0.31; 'class': 0.32; 'another': 0.32; 'quite': 0.32; 'implemented': 0.33; 'classes': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'c++': 0.36; 'functions.': 0.36; 'library.': 0.36; 'much.': 0.36; 'method': 0.36; 'hi,': 0.36; 'should': 0.36; 'received:192.168.2': 0.37; 'two': 0.37; 'easily': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'read': 0.60; 'problems.': 0.60; 'helps': 0.61; 'new': 0.61; 'our': 0.64; 'hints': 0.68; 'results': 0.69; 'loose': 0.84; 'try,': 0.84; 'approach.': 0.91 Date: Wed, 03 Dec 2014 09:29:22 +0100 From: Michael Kreim User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Python, C++ interaction Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417595824 news.xs4all.nl 2910 [2001:888:2000:d::a6]:49022 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81847 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