我已经将
python嵌入到c中,我想知道是否有办法找到
boost :: python :: object的类型是执行python模块的函数后的结果.我有这样的代码:
boost :: python :: object的类型是执行python模块的函数后的结果.我有这样的代码:
- boost::python::object module_ = boost::python::import("..libName");
- boost::python::object result_ = module_.attr("..functionName")(arg1,arg2,...);
- //suppose if the result is int,int a_ = boost::python::extract<int>(result_);
从上面的代码片段,我想知道的是如果有办法找到类型
提取之前的结果.在上面的代码中,result_可以是任何类型,如list,tuple …
解决方法
你可以试试看
- std::vector<std::string> list_to_vector(boost::python::list& l)
- {
- for (int i = 0; i < len(n); ++i)
- {
- boost::python::extract<boost::python::object> objectExtractor(l[i]);
- boost::python::object o=objectExtractor();
- std::string object_classname = boost::python::extract<std::string>(o.attr("__class__").attr("__name__"));
- std::cout<<"this is an Object: "<<object_classname<<std::endl;
- }
- ...................................................
- ...................................................
- }
它适用于我