I have a cdef class in cython and I want to initialize its fields with the setattr builtin function. However, when I do that I got an execution error :
/path/.../cimul.cpython-34m.so in cimul.Simulation.__init__ (cimul.c:5100)()
AttributeError: 'Simulation' object has no attribute 'Re'
My code is as follow:
cdef class Simulation:
cdef double Re, Pr, Ra, a, dt_security
cdef int Nz, NFourier, freq_output, freq_critical_Ra, maxiter
cdef bool verbose
def __init__(self, *args, **kargs):
param_list = {'Re': 1, 'Pr': 1, 'Ra': 1, 'a' : 1, 'Nz': 100,
'NFourier': 50, 'dt_security': 0.9,
'maxiter': 100, 'freq_output': 10,
'freq_critical_Ra':50, 'verbose': False}
# save the default parameters
for param, value in param_list.items():
setattr(self, param, value)
Do you have any idea of how I could circumvent this problem?