本文整理汇总了C++中py::List::length方法的典型用法代码示例。如果您正苦于以下问题:C++ List::length方法的具体用法?C++ List::length怎么用?C++ List::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py::List
的用法示例。
在下文中一共展示了List::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toListOfStrings
Py::List toListOfStrings( Py::Object obj )
{
Py::List list;
if( obj.isList() )
list = obj;
else
list.append( obj );
// check all members of the list are strings
for( Py::List::size_type i=0; i<list.length(); i++ )
{
Py::String path_str( list[i] );
}
return list;
}
示例2: extractException
void PythonInterpreter::extractException(QStringList& errorlist, int& lineno)
{
lineno = -1;
PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
Py_FlushLine();
PyErr_NormalizeException(&type, &value, &traceback);
if(traceback) {
Py::List tblist;
try {
Py::Module tbmodule( PyImport_Import(Py::String("traceback").ptr()), true );
Py::Dict tbdict = tbmodule.getDict();
Py::Callable tbfunc(tbdict.getItem("format_tb"));
Py::Tuple args(1);
args.setItem(0, Py::Object(traceback));
tblist = tbfunc.apply(args);
uint length = tblist.length();
for(Py::List::size_type i = 0; i < length; ++i)
errorlist.append( Py::Object(tblist[i]).as_string().c_str() );
}
catch(Py::Exception& e) {
QString err = Py::value(e).as_string().c_str();
e.clear(); // exception is handled. clear it now.
#ifdef KROSS_PYTHON_EXCEPTION_DEBUG
krosswarning( QString("Kross::PythonScript::toException() Failed to fetch a traceback: %1").arg(err) );
#endif
}
PyObject *next;
while (traceback && traceback != Py_None) {
PyFrameObject *frame = (PyFrameObject*)PyObject_GetAttrString(traceback, const_cast< char* >("tb_frame"));
{
PyObject *getobj = PyObject_GetAttrString(traceback, const_cast< char* >("tb_lineno") );
lineno = PyInt_AsLong(getobj);
Py_DECREF(getobj);
}
if(Py_OptimizeFlag) {
PyObject *getobj = PyObject_GetAttrString(traceback, const_cast< char* >("tb_lasti") );
int lasti = PyInt_AsLong(getobj);
Py_DECREF(getobj);
lineno = PyCode_Addr2Line(frame->f_code, lasti);
}
//const char* filename = PyString_AsString(frame->f_code->co_filename);
//const char* name = PyString_AsString(frame->f_code->co_name);
//errorlist.append( QString("%1#%2: \"%3\"").arg(filename).arg(lineno).arg(name) );
//Py_DECREF(frame); // don't free cause we don't own it.
next = PyObject_GetAttrString(traceback, const_cast< char* >("tb_next") );
Py_DECREF(traceback);
traceback = next;
}
}
if(lineno < 0 && value && PyObject_HasAttrString(value, const_cast< char* >("lineno"))) {
PyObject *getobj = PyObject_GetAttrString(value, const_cast< char* >("lineno") );
if(getobj) {
lineno = PyInt_AsLong(getobj);
Py_DECREF(getobj);
}
}
#ifdef KROSS_PYTHON_EXCEPTION_DEBUG
//krossdebug( QString("PythonInterpreter::extractException: %1").arg( Py::Object(value).as_string().c_str() ) );
krossdebug( QString("PythonInterpreter::extractException:\n%1").arg( errorlist.join("\n") ) );
#endif
PyErr_Restore(type, value, traceback);
}