我需要在各種編碼的python對象和c字符串之間進行轉換。從AC串去使用PyUnicode_Decode,但林不知道如何走另一條路Python c-api和unicode字符串
//char* can be a wchar_t or any other element size, just make sure it is correctly terminated for its encoding
Unicode(const char *str, size_t bytes, const char *encoding="utf-16", const char *errors="strict")
:Object(PyUnicode_Decode(str, bytes, encoding, errors))
{
//check for any python exceptions
ExceptionCheck();
}
我要創建另一個函數,採用Python的Unicode字符串,並使用其放入緩衝區爲Unicode對象是相當簡單的給定encodeing,如:
我懷疑它具有財產以後做然而PyUnicode_AsEncodedString一個返回的PyObject,所以我不知道如何將它放入我的緩衝區...
注:兩上面的方法是C++ Unicode的成員類封裝了Python API中 我使用Python 3.0