我一直在网上搜索,但没找到。我有以下Python代码:class LED(Structure):
_fields_ = [
('color', c_char_p),
('id', c_uint32)
]
class LEDConfiguration(Structure):
_fields_ = [
('daemon_user', c_char_p),
('leds', POINTER(LED)),
('num_leds', c_uint32)
]
下面是一个使用这些结构并返回LEDConfiguration的简化示例函数。在
^{pr2}$
现在这是我使用的C代码(我已经去掉了设置python/调用“parseLedConfiguration”函数/etc所涉及的所有内容,但是如果有帮助的话,我可以添加进来)。在/*Calling the python function "parseLedConfiguration"
pValue is the returned "LEDConfiguration" python Structure*/
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL)
{
int i, num_leds;
PyObject *obj = PyObject_GetAttr(pValue, PyString_FromString("daemon_user"));
daemon_user = PyString_AsString(obj);
Py_DECREF(obj);
obj = PyObject_GetAttr(pValue, PyString_FromString("num_leds"));
num_leds = PyInt_AsLong(obj);
Py_DECREF(obj);
obj = PyObject_GetAttr(pValue, PyString_FromString("leds"));
PyObject_Print(obj, stdout, 0);
我的问题是如何获取返回到最终“obj”的内容。“obj”上的“PyObject_Print”显示以下输出:
我想进入一种状态,在这种状态下,我可以用访问上述“LEDConfiguration”对象的方式访问LP_-LED对象。在
编辑1
我想另一个可能更重要的问题是,我的python代码正确吗?这就是我应该如何将“Structure”的列表或数组存储在另一个“Structure”中,以便可以从pythoncapi访问它吗?在
谢谢!在