Boost::Python Boost:的正向声明:Python::对象抛出Python TypeError
Boost::Python Forward Declaration of boost::python::object throwing python TypeError
我正在尝试重构项目的某些部分,尤其是Python/C++接口。标准的boost::python-python初始化在之前工作
boost::python::object main_module = boost::python::import("__main__");
boost::python::object globals(main_module.attr("__dict__"));
//。。。
然而,在将其分解为自己的一类之后,我得到了
TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies>
当实例化PyInterface对象时,如下所示:
namespace py = boost::python;
class PyInterface
{
private:
py::object
main_module,
global,
tmp;
//...
public:
PyInterface();
//...
};
PyInterface::PyInterface()
{
std::cout << "Initializing..." << std::endl;
Py_Initialize();
std::cout << "Accessing main module..." << std::endl;
main_module = py::import("__main__");
std::cout << "Retrieve global namespace..." << std::endl;
global(main_module.attr("__dict__"));
//...
}
//in test.cpp
int main()
{
PyInterface python;
//...
}
Running gives the following output:
Initializing...
Accessing main module...
Retrieving global namespace...
TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies>
我唯一能想到的是,这与在使用之前声明"globals"有关。在这种情况下,有其他方法可以做到这一点吗?
啊!修复它。
从更改构造函数中对全局变量的调用
globals(main_method.attr("__dict__"));
改为使用赋值运算符:
globals = main_method.attr("__dict__");
回想起来,这似乎是显而易见的,但至少我知道我不是唯一一个因为没有人欺负我而感到困惑的人
相关文章:
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 我应该包含什么来制作 boost.python 扩展?
- 创建一个函数的 Python 绑定,返回指向带有 boost 的向量的指针
- C++ 和 Boost.Python - 如何将变量公开给 python 并在循环中更新它?
- 如何将来自 Boost.Python 的map_indexing_suite与自定义而不是标准对象一起使用?
- Boost Python Numpy - 要初始化的未定义引用
- Boost.Python :C++模板类型匹配的嵌套命名空间
- Boost.Python 列出了所有公开的类和属性
- Boost.Python 在静态库方面失败
- python boost scope 会导致 NoneType 错误
- TypeError:__init__() 应该返回 None,而不是 Python Boost 的 'NoneType'
- 从C++缓冲区到python::boost::list
- 使用C++缓冲区创建PhotoImage:Python 3.3,Python.Boost和Tkinter
- Boost.Python boost::shared_ptr no to python by value convert
- Boost::Python Boost:的正向声明:Python::对象抛出Python TypeError
- python boost::::列表的长度
- c++ Python Boost中的友元函数
- 用Homebrew在Mac OS X上构建python boost hello world-Makefile vs.Re
- 通过Python BOOST使用派生类(c++)