cython に cdef クラスがあり、そのフィールドを setattr 組み込み関数で初期化したいと考えています。ただし、それを行うと、実行エラーが発生しました:
/path/.../cimul.cpython-34m.so in cimul.Simulation.__init__ (cimul.c:5100)()
AttributeError: 'Simulation' object has no attribute 'Re'
私のコードは次のとおりです。
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)
この問題を回避する方法について何か考えがありますか?