Find the type of boost python object
Question: I have been embedding python into c++ and I would like to know if there is a
way to find the type of the boost::python::object which is a result after
executing a function of a python module. I have my code like this:

    
    
    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_);
    

From the above code snippet, what i would like to know is if there is way to
find the type of the result before extracting it. In the above code, the
result_ might be any type like list, tuple...


Answer: You can try this

    
    
    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;
        }
        ...................................................
        ...................................................
     }
    

It works for me.

