1 #ifndef TF2_PY_PYTHON_COMPAT_H
2 #define TF2_PY_PYTHON_COMPAT_H
10 #if PY_MAJOR_VERSION >= 3
11 return PyUnicode_FromStringAndSize(input.c_str(), input.size());
13 return PyString_FromStringAndSize(input.c_str(), input.size());
19 #if PY_MAJOR_VERSION >= 3
22 return PyString_FromString(input);
29 #if PY_MAJOR_VERSION >= 3
31 data = PyUnicode_AsUTF8AndSize(input, &size);
34 PyString_AsStringAndSize(input, &data, &size);
36 return std::string(data, size);
42 PyObject *module = PyImport_Import(py_name);
49 PyObject *r = PyObject_GetAttrString(o, name);