The docs for Python C API describes the pattern of defining a new type:
typedef struct {
PyObject_HEAD
PyObject *first; /* first name */
PyObject *last; /* last name */
int number;
} Noddy;
...
Then methods such as init
could be added.
My question is - what is the point to define custom fields in a struct, why not define them in init
, just like in Python, using PyObject_SetAttr function calls on self
?