diff options
Diffstat (limited to 'src/pyutils.h')
-rw-r--r-- | src/pyutils.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pyutils.h b/src/pyutils.h index d8a46527..54d6fa28 100644 --- a/src/pyutils.h +++ b/src/pyutils.h @@ -126,6 +126,15 @@ struct map_value_type_converter } }; +template <typename T> +PyObject * str_to_py_unicode(const T& str) +{ + using namespace boost::python; + PyObject * pstr = PyString_FromString(str.c_str()); + PyObject * uni = PyUnicode_FromEncodedObject(pstr, "UTF-8", NULL); + return object(handle<>(borrowed(uni))).ptr(); +} + namespace boost { namespace python { // Use expr to create the PyObject corresponding to x |