O'Reilly logo

Learning Cython Programming by Philip Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Object initialization

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 cdef initialization
  • __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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required