[Pyrex] extension type attributes

Greg Ewing greg.ewing at canterbury.ac.nz
Sun May 31 03:26:03 CEST 2009


horace wrote:

> do all attributes have to be cdef? if i want to have a python object as 
> an attribute i have to use
> 
>     cdef object mypythonobject

Effectively, yes, because extension types don't have
a __dict__ and therefore can't have ordinary Python
attributes. (They're like built-in types in that
regard.)

Note that you can use 'public' or 'readonly' to
make these attributes accessible from Python, e.g.

     cdef public object mypythonobject

> and then initialize it in __init__()?

That's optional -- if you don't initialise it, the
initial value will be None.

-- 
Greg



More information about the Pyrex mailing list