Writing SOME class methods in C

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Nov 18 07:52:26 EST 2015


On 18 November 2015 at 07:50, Daniel Haude <dh at dotcom.mfs32> 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



More information about the Python-list mailing list