c – 查找boost python对象的类型

我已经将 python嵌入到c中,我想知道是否有办法找到
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;
    }
    ...................................................
    ...................................................
 }

它适用于我

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...