Commit 93b94788 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved a code snippet from cdef_classes.rst to the examples directory. Added...

Moved a code snippet from cdef_classes.rst to the examples directory. Added cdef readonly to show what it does.
parent 5fadf79e
from sin_of_square cimport Function
cdef class WaveFunction(Function):
# Not available in Python-space:
cdef double offset
# Available in Python-space:
cdef public double freq
# Available in Python-space, but only for reading:
cdef readonly double scale
# Available in Python-space:
@property
def period(self):
return 1.0 / self.freq
@period.setter
def period(self, value):
self.freq = 1.0 / value
...@@ -130,18 +130,4 @@ Attributes in cdef classes behave differently from attributes in regular classes ...@@ -130,18 +130,4 @@ Attributes in cdef classes behave differently from attributes in regular classes
- Attributes are by default only accessible from Cython (typed access) - Attributes are by default only accessible from Cython (typed access)
- Properties can be declared to expose dynamic attributes to Python-space - Properties can be declared to expose dynamic attributes to Python-space
:: .. literalinclude:: ../../examples/tutorial/cdef_classes/wave_function.pyx
cdef class WaveFunction(Function):
# Not available in Python-space:
cdef double offset
# Available in Python-space:
cdef public double freq
# Available in Python-space:
@property
def period(self):
return 1.0 / self.freq
@period.setter
def period(self, value):
self.freq = 1.0 / value
<...>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment