Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stefan Behnel 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: References: 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: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99693 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