Skip to content

Commit 3a37183

Browse files
committed
Make get_string_from_python Python2 compatible
1 parent 639b137 commit 3a37183

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/scorepy/pythonHelpers.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ auto cast_to_PyFunc(TFunc* func) -> detail::ReplaceArgsToPyObject_t<TFunc>*
7676
inline CString get_string_from_python(PyObject& o)
7777
{
7878
Py_ssize_t len;
79+
#if PY_MAJOR_VERSION >= 3
7980
const char* s = PyUnicode_AsUTF8AndSize(&o, &len);
81+
#else
82+
const char* s = PyString_FromStringAndSize(&o, &len);
83+
#endif
8084
return CString(s, len);
8185
}
8286

0 commit comments

Comments
 (0)