Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'cpython': 0.05; 'subject:code': 0.07; 'python:': 0.09; 'subject:modules': 0.09; 'wrapper': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language,': 0.12; 'project,': 0.12; 'non-python': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'written': 0.21; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'michael': 0.29; 'strongly': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'lines': 0.31; 'that.': 0.31; 'subject:that': 0.31; 'types.': 0.31; 'maybe': 0.34; 'subject:from': 0.34; "can't": 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessible': 0.36; 'url:org': 0.36; 'sometimes': 0.38; 'short': 0.38; 'read': 0.60; 'easy': 0.60; 'most': 0.60; "you'll": 0.62; 'making': 0.63; 'to:addr:gmail.com': 0.65; 'hand': 0.80; 'oscar': 0.84; 'subject:source': 0.84; 'cutting': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=Jg9/NZfIf5nUVXWmt6CSYqIXMRZ7pZmCb9BqpFOVOVU=; b=eCfWZ0xoglEQhFVB7KVDV3784jPk2HRygg20DDfmhTE/Fxon/B1BzIiyhYxPehkGU4 ofhahD2MhIWcqHcaPliSmO8IKKaRzb2Ps51XmrsUzsmTrF00FNSfO4cNdbW1uf7/BCue Ae+KdUJ+8WIAhgFjCycQxFcnCsjNnHMKm1dyxk/t5hwDWRSZFmkR7OfwAA70BXvvo+CE oW2QGWih7126BPnBGgtROv9wv5WLTV9l6HAERcB1jpq7N+qfyWoHOFKAWqeTGly4PQPx 7u5sNc1qPNrtcjQhbBWieqoWrWyFSBo5q2yYLzkmbX/m9anO8+JsWyV2cB2eajqUF8pZ 6YlA== X-Received: by 10.220.143.80 with SMTP id t16mr6478929vcu.10.1380790925056; Thu, 03 Oct 2013 02:02:05 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Oscar Benjamin Date: Thu, 3 Oct 2013 10:01:44 +0100 Subject: Re: Running code from source that includes extension modules To: Michael Schwarz 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380790933 news.xs4all.nl 15966 [2001:888:2000:d::a6]:33306 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55406 On 2 October 2013 23:28, Michael Schwarz wrote: > > I will look into that too, that sounds very convenient. But am I right, t= hat to use Cython the non-Python code needs to be written in the Cython lan= guage, which means I can't just copy&past C code into it? For my current pr= oject, this is exactly what I do, because the C code I use already existed. It's better than that. Don't copy/paste your code. Just declare it in Cython and you can call straight into the existing C functions cutting out most of the boilerplate involved in making C code accessible to Python: http://docs.cython.org/src/userguide/external_C_code.html You'll sometimes need a short Cython wrapper function to convert from Python types to corresponding C types. But this is about 5 lines of easy to read Cython code vs maybe 30 lines of hard to follow C code. Having written CPython extension modules both by hand and using Cython I strongly recommend to use Cython. Oscar