Skip to content Skip to sidebar Skip to footer

Python C-api And Unicode Strings

I need to convert between python objects and c strings of various encodings. Going from a c string to a unicode object was fairly simple using PyUnicode_Decode, however Im not sure

Solution 1:

I suspect it has somthing to do with PyUnicode_AsEncodedString however that returns a PyObject so I'm not sure how to put that into my buffer...

The PyObject returned is a PyStringObject, so you just need to use PyString_Size and PyString_AsString to get a pointer to the string's buffer and memcpy it to your own buffer.

If you're looking for a way to go directly from a PyUnicode object into your own char buffer, I don't think that you can do that.

Post a Comment for "Python C-api And Unicode Strings"