[Cython] Storing many, many instances

Stefan Behnel stefan_ml at behnel.de
Tue May 5 18:57:39 CEST 2009


Stéfan van der Walt wrote:
> 1. Define your class in myclass.pyx:
> 
> cdef class MyClass:
>     cdef test(self):
>         print "hello!"
> 
> 2. Define a pxd "header" file:
> 
> cdef class MyClass:
>     cdef test(self)
> 
> 3. Use *both* cimport and normal import:
> 
> from myclass cimport MyClass as MyClassT
> from myclass import MyClass
> 
> cdef MyClassT m = MyClass()

Note that this will generate unnecessary type checks in the code as Cython
cannot know that both types are identical. There should be no reason to
import both, just stick with the cimport.

Stefan



More information about the Cython-dev mailing list