Hi all! Big fan of Cython thus far -- many thanks to the devs.
I'm trying to figure out how to save some typing and maintenance -- I
have a bunch of flat C variables in a "breakfast::stats"
pseudo-namepsace like the following in libbreakfast.pxd:
cdef extern from "breakfast_stats.h":
int breakfast_stats_spams_eaten
int breakfast_stats_hams_eaten
int breakfast_stats_eggs_eaten
But I'd like to turn it into a stats "singleton", accessible from an
interpreted environment like so:
>>> import libbreakfast
>>> libbreakfast.stats.spams_eaten
12
>>> libbreakfast.stats.hams_eaten = 3
I know I can create a separate Cython module to have a similar effect,
but I'm trying to learn the Cython language, so let's assume I want to
keep it all in a single module.
In Python, I would have the option of using a Stats class with
__getattr__/__setattr__ defined to prefix the attr_name with
'breakfast_stats_' and proxy to globals() -- this would prevent me
from having to break out each property explicitly, and the Cython code
would not need to be updated each time a stat were added or removed.
Is there a way that I can achieve a similar result in Cython?
- Leary
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev