Reputation: 38949
I'm trying to make a Cython class that has some attributes that need to be accessible from Python. Right now, the cleanest way I can think of doing that is using @property
to explicitly define getters and setters like so:
@property
def some_attr(self):
return self._some_attr
@some_attr.setter
def some_attr(self, unicode val):
self._some_attr = val
This feels like a lot of extraneous and verbose boiler plate to me. Is there no built-in way to just do this with a decorator in Cython?
Upvotes: 2
Views: 187
Reputation: 281046
The keyword to define an attribute as accessible at Python level is public
:
cdef class Foo:
cdef public unicode some_attr
...
Upvotes: 2