我执行了这个python脚本。这一行发生了一个错误
t = gdcm.Orientation.GetType(dircos)错误信息是:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2820, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-8-fb43b0929780>", line 1, in <module>
gdcm.Orientation.GetType(dircos)
TypeError: expected a list.我查了一下类引用。上面写着
输入是一个6倍的数组。
变量dircos正好是一个包含6个元素的列表,
>>> dircos
Out[11]: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]我不知道为什么会出错。
发布于 2016-04-04 04:19:16
我检查了源代码,发现它实际上检查了tuple。这一信息具有误导性。
// Grab a 6 element array as a Python 6-tuple
%typemap(in) const double dircos[6] (double temp[6]) { // temp[6] becomes a local variable
int i;
if (PyTuple_Check($input) /*|| PyList_Check($input)*/) {
if (!PyArg_ParseTuple($input,"dddddd",temp,temp+1,temp+2,temp+3,temp+4,temp+5)) {
PyErr_SetString(PyExc_TypeError,"list must have 6 elements");
return NULL;
}
$1 = &temp[0];
} else {
PyErr_SetString(PyExc_TypeError,"expected a list.");
return NULL;
}
}您需要传递一个元组:
>>> import gdcm
>>> dircos = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
>>> gdcm.Orientation.GetType(tuple(dircos))
1https://stackoverflow.com/questions/36393896
复制相似问题