Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Oscar Benjamin Newsgroups: comp.lang.python Subject: Re: Writing SOME class methods in C Date: Wed, 18 Nov 2015 12:52:26 +0000 Lines: 19 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de iwDQh70UpcSxLSJI5eFHngOD7mJIJ5Fds0v7l8fGVsxQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'remaining': 0.07; 'cc:addr :python-list': 0.09; 'subclass': 0.09; 'subject:Writing': 0.09; 'python': 0.10; 'suggest': 0.15; '(but': 0.15; '07:50,': 0.16; 'cc:name:python list': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'too).': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'trying': 0.22; 'daniel': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'methods.': 0.29; "i'm": 0.30; 'classes': 0.30; 'code': 0.30; 'implement': 0.32; 'compiled': 0.32; 'class': 0.33; 'add': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'suggestion': 0.37; 'received:209': 0.38; 'some': 0.40; 'your': 0.60; 'entire': 0.61; 'here.': 0.62; '(that': 0.63; 'oscar': 0.84 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; bh=R6MCyKw1Y7ImAKaqkx70addxuWEdG8lblAfN2c3LlHE=; b=nAFshdomTnbQ8SkUXnMbzeErhQTATgOJCOpTU+4iEcb2RO/MvHIaOaCpz8KMQOBkQm cf6kJ/DX8I8hVSWN1xqDhK8RkNMtL6EM56EWtzLNQcsGRTdv4WLKw9LXe2lDVKLKsR7w DhGuaSDqiknrysqqZgVTz9F16lXXnyUPIxG4uZORG6Cvl1KGRr4T83aSAcpgXk3SKQUT JOBXgiTDmP1+rT+4QNU8x5/h7BG5vqnsHwvjPXiC3TJb5heBTODhiMAAT1mKR5DJn6sT yTJ0LPD3ivE+XEnL+YrAKAWxYs+m7vf9MRCbyXdFmBiRBQvctrGEZQTEvWO4gwOVlxfp TC2w== X-Received: by 10.25.81.13 with SMTP id f13mr652410lfb.126.1447851166663; Wed, 18 Nov 2015 04:52:46 -0800 (PST) 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:98964 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. Alternatively Terry's suggestion to implement a class in C and then subclass it in Python to add the remaining methods is a good one. But then I would write the C class using Cython so I may as well do the whole thing in Cython. -- Oscar