How to instantiate a custom Python class inside a C extension?

Musbur musbur at posteo.org
Wed Apr 1 13:24:11 EDT 2020


Am 01.04.2020 15:01 schrieb Rhodri James:

> I believe you do it in C as you would in Python: you call the Series 
> class!
> 
> pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);

Well, that dumps core just as everything else I tried.

What does work, however, is calling PyType_Ready first:

     PyType_Ready(&series_type);
     pyseries = PyObject_New(Series, &series_type);
     PyObject_Init((PyObject *)pyseries, &series_type);o

I don't understand, though, why I have to do that and when. Didn't that 
already happen when the module was imported? Do I need to do it whenever 
I create a new instance in C?


More information about the Python-list mailing list