Home > OS >  How to build a class in C to use in Python?
How to build a class in C to use in Python?

Time:11-20

PyMethodDef from Python.h allows to specify Cpp-built functions to use in Python. However, there is much doubt if this can be applied for Cpp-built classes and I can't find anything like PyClassDef which could presumably help me to do so. All I've managed to find concerns class methods, but not the class itself. Is it possible to build a class in C with regular Python-C-API to use as a regular class in Python?

CodePudding user response:

You can use pybind11 to implement python call c native class. Link here pybind11 class it's easier use than cpython.

CodePudding user response:

Is this: https://docs.python.org/3.8/extending/newtypes_tutorial.html#adding-data-and-methods-to-the-basic-example what you are looking for? I am not sure that I understood the question correctly.

  • Related