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


Groups > comp.lang.python > #31387

Re: Providing a Python wrapper to a C++ type.

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; '16,': 0.03; 'subject:Python': 0.05; 'wrapper': 0.07; 'api': 0.09; 'python': 0.09; 'defined,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'specific.': 0.09; 'url:)': 0.13; '(unlike': 0.16; 'curious.': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'url:html)': 0.16; 'wrappers': 0.16; 'wrote:': 0.17; 'stefan': 0.17; 'module': 0.19; 'python?': 0.20; 'least': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'implemented': 0.27; 'c++': 0.27; 'interface': 0.27; 'header:X-Complaints-To:1': 0.28; 'this?': 0.28; 'wrap': 0.29; 'this.': 0.29; 'worked': 0.30; 'code': 0.31; 'url:python': 0.32; '(2)': 0.32; 'quickly': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; "can't": 0.34; 'agree': 0.34; '(1)': 0.34; 'doing': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'october': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'url:index': 0.61; 'email addr:gmail.com': 0.63; 'yourself': 0.77; 'mind:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Providing a Python wrapper to a C++ type.
Date Tue, 16 Oct 2012 13:39:23 +0200
References <b71bb1ac-cfe0-45eb-a384-4d6109c99543@googlegroups.com> <0423426c-c19a-4634-9f67-5bf92d766f61@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host fw-snc-frn5-de01.fw.telefonica.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120912 Thunderbird/15.0.1
In-Reply-To <0423426c-c19a-4634-9f67-5bf92d766f61@googlegroups.com>
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>
Newsgroups comp.lang.python
Message-ID <mailman.2263.1350387583.27098.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350387583 news.xs4all.nl 6954 [2001:888:2000:d::a6]:52262
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31387

Show key headers only | View raw


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

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


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