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


Groups > comp.lang.python > #99693

Re: Writing SOME class methods in C

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stefan Behnel <stefan_ml@behnel.de>
Newsgroups comp.lang.python
Subject Re: Writing SOME class methods in C
Date Sun, 29 Nov 2015 14:26:41 +0100
Lines 24
Message-ID <mailman.8.1448803612.14615.python-list@python.org> (permalink)
References <slrnn4obfa.db7.dh@dotcom.mfs32> <CAHVvXxSEN5PYeJ==u=fWKxAkmsZXU8FhsFOFDQd_05T8M5OgBw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de L1iiXCE71wSouiyyaL4OFAS1cS1Q/sAE2SFyTkQW27nA==
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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(using': 0.07; 'extends': 0.07; 'benjamin': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Writing': 0.09; 'python': 0.10; 'suggest': 0.15; '(but': 0.15; '07:50,': 0.16; 'bugs.': 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:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'too).': 0.16; 'wrote:': 0.16; 'stefan': 0.18; '2015': 0.20; 'extension': 0.20; 'trying': 0.22; 'code.': 0.23; 'daniel': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'methods.': 0.29; "i'm": 0.30; 'classes': 0.30; 'code': 0.30; 'strongly': 0.30; 'extend': 0.31; 'implement': 0.32; 'compiled': 0.32; 'class': 0.33; 'done': 0.35; 'modules': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'or,': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'your': 0.60; 'entire': 0.61; 'real': 0.62; 'here.': 0.62; '(that': 0.63; 'more': 0.63; 'inherit': 0.66; 'here': 0.66; 'fact,': 0.67; 'fast,': 0.84; 'oscar': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host ipservice-092-217-127-132.092.217.pools.vodafone-ip.de
X-Enigmail-Draft-Status N1110
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
In-Reply-To <CAHVvXxSEN5PYeJ==u=fWKxAkmsZXU8FhsFOFDQd_05T8M5OgBw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:99693

Show key headers only | View raw


Oscar Benjamin schrieb am 18.11.2015 um 13:52:
> On 18 November 2015 at 07:50, Daniel Haude wrote:
>>
>> I'm trying to implement some (but not all) methods of a Python class in C.
>> What I've found on the Net is:
>>  - how to implement entire modules in C so that I can import that module and
>>    use the C functions (successfully done it, too).
>>  - how to implement entire classes in C
> 
> I would suggest to use Cython here. You can write your class in Python
> (that will be compiled to C) and then call out to any C code from any
> of its methods.

Or, in fact, do the reverse: Implement the base class in Cython and inherit
from it in a Python class that extends it. That would give you a fast,
native extension type at the base and leaves you with all the freedom to
extend it in Python code or even natively in other Cython code.

I strongly recommend not to resort to writing real C code here (using the
C-API of CPython). It will be slower and will contain more bugs.

Stefan

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


Thread

Writing SOME class methods in C Daniel Haude <dh@dotcom.mfs32> - 2015-11-18 07:50 +0000
  Re: Writing SOME class methods in C Terry Reedy <tjreedy@udel.edu> - 2015-11-18 04:47 -0500
  Re: Writing SOME class methods in C Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-18 12:52 +0000
  Re: Writing SOME class methods in C Stefan Behnel <stefan_ml@behnel.de> - 2015-11-29 14:26 +0100

csiph-web