本文整理汇总了C++中PythonWrapper::invoke_object方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonWrapper::invoke_object方法的具体用法?C++ PythonWrapper::invoke_object怎么用?C++ PythonWrapper::invoke_object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonWrapper
的用法示例。
在下文中一共展示了PythonWrapper::invoke_object方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: node_dropped
void node_dropped(DomNode* node)
{
map<DomNode*, PyObject*>::iterator iter = dom_relation.find(node);
if (iter != dom_relation.end())
{
PyObject* py_node = iter->second;
python.invoke_object(py_node, "drop_tree");
}
}
示例2: build_dom_tree
// build dom tree from python lxml dom tree.
DomNode* build_dom_tree(DomNode* parent, PyObject* node, map<DomNode*, PyObject*>& relation)
{
const char* tag = python.get_attr_string(node, "tag");
const char* inner_text = python.get_attr_string(node, "text");
const char* inner_tail = python.get_attr_string(node, "tail");
string text;
if (inner_text != NULL)
{
text.append(inner_text);
}
if (inner_tail != NULL)
{
if (parent != NULL)
{
parent->append_text(inner_tail);
}
}
DomNode* dom_node = new DomNode(tag, text);
relation[dom_node] = node;
//PyObject* parent = python.invoke_object(node, "getparent");
FILE* fp = fopen("object.txt", "w+");
PyObject_Print(node, fp, Py_PRINT_RAW);
fclose(fp);
PyObject* children = python.invoke_object(node, "getchildren");
if (children != NULL)
{
int count = PyList_GET_SIZE(children);
for (int i = 0; i < count; ++i)
{
PyObject* child = PyList_GET_ITEM(children, i);
if (PyObject_IsInstance(child, tag_type) != 1)
{
continue;
}
DomNode* child_node = build_dom_tree(dom_node, child, relation);
dom_node->append_child(child_node);
}
}
dom_node->add_attribute("class", get_dom_attr(node, "class"));
dom_node->add_attribute("id", get_dom_attr(node, "id"));
return dom_node;
}