C Python extension to export an Function

Stefan Behnel stefan_ml at behnel.de
Thu Sep 1 09:02:42 EDT 2016


Ganesh Pal schrieb am 01.09.2016 um 14:30:
> On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote:
>> Ganesh Pal writes:
>>> Iam pretty new to C Python extension , I was able to export few simple
>>> modules to python and it look like the cool thing to do ...
>>
>> Maybe, it is a good idea to have a look at "cython".
>>
>> "cython" is a compiler. It translates Python code enhanced with
>> special annotations into C. The annotations mostly tell the compiler
>> that something ("object", "method", "function", ...) should be at "C"
>> rather than "Python" level, thus avoiding much of Python's overhead
>> and allows to do things possible in "C" but not in "Python".
>>
>> Developing safe "C" extensions for Python is difficult. You
>> need some quite deep understanding of the Python-C interface
>> and must be very careful to observe all requirements (especially
>> those related to proper reference management).
>>
>> Developing "C" extensions with "cython" is much easier as
>> "cython" hides many of the complexities and takes care of most
>> requirements.
> 
> Really appreciate the reply and your suggestion on  trying to use "cython"
> ,  but my whole idea of using  "C" extension is to regular C codes .  We
> have bunch of C code that's already available and   C -Python seems to suit
> me better

>From your response it's not obvious whether you are aware that Cython also
makes it substantially easier to *interface* CPython with external C code,
in the same way that it makes it easy (but not necessary) to *avoid*
writing C in the first place. So I thought I'd just mention that this is
not a reason to rule it out as an excellent option.

Stefan





More information about the Python-list mailing list