[C++-sig] boost::python::str and Python's str and unicode types

Stefan Seefeld seefeld at sympatico.ca
Thu Jul 23 17:22:13 CEST 2009


On 07/23/2009 10:17 AM, Robert Smallshire wrote:
> Hello,
>
> I'm looking for some confirmation that my understanding of what
> boost.python is doing is correct.
>
> > From what I understand boost::python::str represents the str
> (PyStringObject) type in Python.  Unless I'm missing something, here
> doesn't seem to be anything like boost::python::unicode representing the
> unicode type (PyUnicodeObject).
>
> Boost.Python does have a built-in conversion from std::wstring to
> object, but this creates a str in Python, so presumably there is some
> (lossy?) decoding going on here.
>
> It seems that to directly create a PyUnicodeObject from C++ I will need
> to do one or more of the following:
>
> 1) Directly use the Python C API to create and manipulate
> PyUnicodeObject.
> 2) Create my own subclass of boost::python::object called for example
> 'unicode', which would be similar to the str class provided out of the
> box, but would use PyUnicodeObject underneath and deal with wchar_t
> rather than char.
>    

You might want to talk to Haoyu Bai, who is presently working on the 
Python 3 port of boost.python. I wonder whether some of his work would 
be useful with Python 2, notably the unicode stuff. Haoyu, any thoughts 
on this ?

Regards,
         Stefan

-- 

       ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list