Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31390
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <nawijn@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; '16,': 0.03; 'subject:Python': 0.05; 'c++,': 0.07; 'wrapper': 0.07; 'api': 0.09; 'python': 0.09; 'defined,': 0.09; 'specific.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'url:)': 0.13; '(but': 0.15; '(unlike': 0.16; 'curious.': 0.16; 'url:html)': 0.16; 'wrappers': 0.16; 'wrote:': 0.17; 'stefan': 0.17; 'module': 0.19; 'code.': 0.20; 'python?': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'implemented': 0.27; 'c++': 0.27; 'interface': 0.27; 'this?': 0.28; 'wrap': 0.29; 'case,': 0.29; 'this.': 0.29; 'worked': 0.30; 'e.g.': 0.30; 'code': 0.31; 'url:python': 0.32; '(2)': 0.32; 'quickly': 0.32; 'could': 0.32; "can't": 0.34; 'agree': 0.34; 'received:google.com': 0.34; '(1)': 0.34; 'doing': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'october': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'url:docs': 0.38; 'performance': 0.39; 'easily': 0.39; 'where': 0.40; 'end': 0.40; 'your': 0.60; 'url:index': 0.61; 'between': 0.63; 'email addr:gmail.com': 0.63; 'differences': 0.65; 'yourself': 0.77; 'mind:': 0.84 |
| Newsgroups | comp.lang.python |
| Date | Tue, 16 Oct 2012 04:46:17 -0700 (PDT) |
| In-Reply-To | <mailman.2263.1350387583.27098.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=137.17.109.98; posting-account=QNsEXgoAAABu_Avbf026MEK8WO7y27Mt |
| References | <b71bb1ac-cfe0-45eb-a384-4d6109c99543@googlegroups.com> <0423426c-c19a-4634-9f67-5bf92d766f61@googlegroups.com> <mailman.2263.1350387583.27098.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 137.17.109.98 |
| MIME-Version | 1.0 |
| Subject | Re: Providing a Python wrapper to a C++ type. |
| From | Marco Nawijn <nawijn@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.2265.1350387982.27098.python-list@python.org> (permalink) |
| Lines | 77 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1350387982 news.xs4all.nl 6970 [2001:888:2000:d::a6]:56815 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31390 |
Show key headers only | View raw
On Tuesday, October 16, 2012 1:39:44 PM UTC+2, Stefan Behnel wrote: > Marco Nawijn, 16.10.2012 12:17: > > > On Tuesday, October 16, 2012 10:11:52 AM UTC+2, aaron.l...@gmail.com wrote: > > >> I have a C++ module where I have a defined, working type. How would I > > >> make a wrapper for this type to be able to be used in Python? I am > > >> familiar(-ish) with the C-API for functions but I can't see concretely how > > >> one would include an interface to a type. > > >> > > >> Is it this? http://docs.python.org/release/2.7.3/extending/newtypes.html > > > > > > There are a few ways of doing this. At least three come to my mind: > > > 1. Wrap the C++ type yourself by using handcrafted code implemented with the Python C API > > > 2. Use SWIG to wrap the C++ code and (semi) automatically create the wrapper (http://www.swig.org/) > > > 3. Use BOOST Python to wrap the C++ code (http://www.boost.org/doc/libs/1_51_0/libs/python/doc/index.html) > > > > > > I would highly discourage (1) unless you are very brave and curious. Ofcourse it is a nice excercise, but if you want something to work quickly I would recommend to use either (2) or (3). > > > > > > I have used both SWIG and BOOST Python and either of them worked pretty well for me. In the end I selected BOOST Python, because I was only interested in the Python wrapping (SWIG could generate many other wrappers as well). > > > > There's also Cython, which provides a very flexible way (unlike SWIG) of > > doing these things easily (unlike C++ with Boost). > > > > http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html > > > > I agree with discouraging 1) in specific. > > > > Stefan Hi Stefan, I never worked with Cython (but I know it is very powerful and interesting) but in my mind there are slight differences in usage scenario between e.g. Boost Python and Cython. For me the idea of Cython is that your main code is in Python, but you want to improve the performance of specific parts of the code. In that case, Cython is the way to go. In case of Boost Python, the scenario for me is that you have a main program/library in C++, but you want to be able use the functionality from Python. Do you agree with this view? Marco
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Providing a Python wrapper to a C++ type. aaron.l.france@gmail.com - 2012-10-16 01:11 -0700
Re: Providing a Python wrapper to a C++ type. Marco Nawijn <nawijn@gmail.com> - 2012-10-16 03:17 -0700
Re: Providing a Python wrapper to a C++ type. Stefan Behnel <stefan_ml@behnel.de> - 2012-10-16 13:39 +0200
Re: Providing a Python wrapper to a C++ type. Marco Nawijn <nawijn@gmail.com> - 2012-10-16 04:46 -0700
Re: Providing a Python wrapper to a C++ type. Stefan Behnel <stefan_ml@behnel.de> - 2012-10-16 14:16 +0200
Re: Re: Providing a Python wrapper to a C++ type. Evan Driscoll <driscoll@cs.wisc.edu> - 2012-10-16 11:42 -0500
Re: Providing a Python wrapper to a C++ type. Christian Gollwitzer <auriocus@gmx.de> - 2012-10-16 21:03 +0200
Re: Providing a Python wrapper to a C++ type. Marco Nawijn <nawijn@gmail.com> - 2012-10-16 04:46 -0700
csiph-web