C Python extension to export an Function

Ganesh Pal ganesh1pal at gmail.com
Thu Sep 1 11:24:27 EDT 2016


Thanks stefan and  Gollwitzer  , good to know there are many ways to do this
i.e via cython or SWIG   but  the C/Python API
<https://docs.python.org/2/c-api/> is probably the most widely used method
- not for it’s simplicity but for the fact that you can manipulate python
objects in your C code.

I want to use C/Python API <https://docs.python.org/2/c-api/>

On Thu, Sep 1, 2016 at 6:32 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> 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
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list