[Pyrex] Access to nested structures and arrays

Francesc Altet faltet at carabos.com
Tue Mar 20 08:30:13 UTC 2007


El dt 20 de 03 del 2007 a les 12:42 +1200, en/na Greg Ewing va escriure:
> Pierre GM wrote:
> 
> > And define "parameter_flags" as a "model flag" instance.
>  > And I can't set it to public as it's a non-generic one.
> 
> Okay, I see what the problem is now. Pyrex disallows
> writable non-generic public attributes because the mechanism
> for accessing them doesn't allow for performing a type check,
> so there would be nothing to stop Python code from assigning
> an object of the wrong type.
> 
> You can expose it readonly, however:
> 
>     cdef class loess_model:
>        cdef readonly modelflags parameter_flags
> 
> (It's only readonly from Python code -- Pyrex still has
> full access to it.)
> 
> Is this sufficient for what you want to do?

Another possibility could be to declare a Python class (in Python space)
having a ndarray attribute. Then, create a Pyrex extension that inherits
from this Python class. In this extension, you could map the ndarray
attribute data area (inherited from the Python class) to the C list.
With this, you should be able to write to this area from both Python and
Pyrex spaces.

Hope this helps,

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth




More information about the Pyrex mailing list