object の属性を取得する

attr 関数を使う。

object を C++ の型に変換する も参照のこと。

構文

namespace boost::python
{
    class object
    {
    public:
        const_object_attribute attr(const object&) const;
        object_attribute attr(const object&);
    }
}

具体例

#include <stdio.h>
#include <boost/python.hpp>
#include <string>

namespace python = boost::python;
using std::string;

void print_str(python::object obj)
{
    python::object string_attribute = obj.attr("__str__");
    string expression = python::extract<string>(string_attribute());
    printf("%s\n", expression.c_str());
}

ソースコード

参考

results matching ""

    No results matching ""