我想一個C++轉換緩衝到一個python ::升壓::名單,我的C++類是:從C++緩衝區蟒蛇::升壓::名單
#include "boost/python/list.hpp"
using namespace boost::python;
class Buffer {
public:
unsigned char* m_pBuff;
int m_iWidth;
int m_iHeight;
Buffer(cont int p_iWidth, const int p_iHeight) {
m_pBuff = new unsigned char[p_iWidth * p_iHeight];
m_iWidth = p_iWidth;
m_iHeight = p_iHeight;
}
~Buffer() { delete[] m_pBuff; }
/* Class Functions */
list getList (void) {
list l;
l.append(m_iWidth);
l.append(m_iHeight);
std::string data(m_iWidth * m_iHeight, ' ');
unsigned char* pBuff = m_pBuff;
for (int i = 0; i < m_iWidth * m_iHeight; ++i, ++pBuff) {
data[i] = (char*) *pBuff;
}
l.append(data);
return l;
}
};
而蟒蛇升壓模塊定義爲:
using namespace boost::python;
BOOST_PYTHON_MODULE(BufferMethods)
{
class_<Buffer>("Buffer", init<const int, const int>())
.add_property("width", &Buffer::m_iWidth)
.add_property("height", &Buffer::m_iHeight)
/* Other functions */
.def("getList", &Buffer::getList)
;
}
但是當我在Python運行模塊它返回此錯誤:
>>> from BufferMethods import *
>>> Buff = Buffer(800, 600)
>>> dataList = Buff.getList()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 0: invalid continuation byte
>>>
我在做什麼錯?我正在使用Python 3.3。
所以它是'boost :: python :: list',而不是'python :: boost :: list',不是嗎? –