You may remember from our garbage collection example earlier in the book that when defining a class in Cython, we have two initialization hooks for a class:
__cinit__: Used for
__init__: Used for normal Python initialization
Both of these have uses and sometimes you use both. The
__cinit__ hook is used before the Python
__init__ hook and is only called once! By convention, this is used to allocate memory for C structs wrapped as Python classes. But the
__init__ hook works just like any normal Python
__init__ hook and you can call this as much as you want to.