沒有屬性我有奇怪的問題與SWIG(C +蟒)SWIG,PY + C:下指針
在C中,我有一個返回指向struct elements_t
的功能。我稱之爲蟒functon,得到的結果(指針),但我不能訪問結構的元素..
typedef struct elements elements_t;
struct elements {
int nelements;
// ... other stuff
};
elements_t* get_elements()
{
elements_t* p;
// ...
return p;
}
而且在python我做的:
r = clibrary.get_elements()
print r
# <Swig Object of type 'elements_t *' at 0xb77029f8>
print r.nelements
# AttributeError: 'SwigPyObject' object has no attribute 'nelements'
所以我得到的最後錯誤是沒有nelements
,即使p
指向一個結構合理...
是的,錯誤的問題。代碼仍然不起作用:( – 2012-01-28 11:17:29
好吧,因爲r是一個指向結構的指針,是否有可能返回結構體?我正在查看http://www.swig中的「31.3.6結構體」一節.org/Doc1.3/Python.html並且有一些例子。 – 2012-01-28 11:25:44