[Cython] User Question - Questions and 'Cannot convert to Python Object'...

Santiago Aguiar santiago.aguiar at gmail.com
Fri Mar 13 20:39:54 CET 2009


Lisandro Dalcin wrote:
> Santiago, have you considered writing a simple script to generate
> Cython code :-) ?? You could parse a simple txt file with metadata
> about your C-level structs (name, field types, fieldname, and even
> default field values), then you could easily dump Cython code
> automating the member, __cinit__() methods and all the 'property' you
> need.
>   
I did, and I'm usually on for codegen, but since I was on a schedule I 
wanted to avoid having to code the generator, and hoped that something 
already existed.... besides, the metadata will still have to mirror the 
C defs... or I would need to parse the .h which... well I want to avoid 
if at all possible! However, it still could save me some time.
> As Stefan commented, you should just store your struct in your cdef
> class, and use 'property' to expose the field values with tiny get/set
> funcions... Remember that struct member assignments should work in any
> C89 compiler... No point to complicate your from_c()/ to_c() cdef
> methods ...
>   
OK, I'm not terribly convinced that I will save some time by writing the 
get/set instead of the from_c to_c, but I'm going to try it!

Thanks for the comments!!

Regards,

Santiago.


More information about the Cython-dev mailing list