|
PLearn 0.1
|
#include <PythonObjectWrapper.h>
Static Public Member Functions | |
| static string | convert (PyObject *, bool print_traceback) |
Definition at line 314 of file PythonObjectWrapper.h.
| string PLearn::ConvertFromPyObject< string >::convert | ( | PyObject * | pyobj, |
| bool | print_traceback | ||
| ) | [static] |
Definition at line 152 of file PythonObjectWrapper.cc.
References PLASSERT, PLERROR, and PLearn::PLPythonConversionError().
{
PLASSERT(pyobj);
// if unicode, encode into a string (utf8) then return
if(PyUnicode_Check(pyobj))
{
PyObject* pystr= PyUnicode_AsUTF8String(pyobj);
if(!pystr)
{
if(PyErr_Occurred()) PyErr_Print();
Py_DECREF(pystr);
PLERROR("in ConvertFromPyObject<string>::convert : "
"Unicode to string conversion failed.");
}
string str= PyString_AsString(pystr);
Py_DECREF(pystr);
return str;
}
// otherwise, should already be a string
if(!PyString_Check(pyobj))
PLPythonConversionError("ConvertFromPyObject<string>", pyobj,
print_traceback);
return PyString_AsString(pyobj);
}

1.7.4