-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Description
In Python 3, std::string is incorrectly converted to python 'str' type. It should be converted to 'bytes' type. Pull request #54 probably solves this issue.
Code of str_test module:
#include <boost/python.hpp>
std::string getString()
{
return "string";
}
std::wstring getWString()
{
return L"wstring";
}
BOOST_PYTHON_MODULE( str_test )
{
boost::python::def( "getString", &getString );
boost::python::def( "getWString", &getWString );
}
First example is Python 2 and shows correct results.
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from str_test import getString, getWString
>>> type(getString())
<type 'str'>
>>> type(getWString())
<type 'unicode'>
Second example is Python 3 and shows that std::string is unexpectedly converted to 'str'.
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from str_test import getString, getWString
>>> type(getString())
<class 'str'> # ooops!!! expected bytes there!
>>> type(getWString())
<class 'str'>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels