问题描述
.cpp文件:
boost::python::object mod;
void init_mod(boost::python::object o){
mod = o;
}
// some code
BOOST_PYTHON_MODULE(MyModule){
def("init_mod",&init_mod);
// for the other code
}
从python中,我导入模块并为其分配:
from ..utilities import foo as foo_module
init_mod(foo_module)
在foo中,我有一个名为Foo的类,以及一个可以返回Foo对象的包装器函数
class Foo:
def __init__(self,i,j,k):
self._i = i
self._j = j
self._k = k
self._done = False
def wrapper_foo(i,k):
return Foo(i,k)
在同一个C ++文件中,我尝试创建一个Foo对象,但它返回None:
Bar* create_foo(){
// this returns None
boost::python::object foo = mod.attr("Foo")(1,2,3);
foo.attr("_done") = true; // nonetype has no attribute _done error
// this also returns None
boost::python::object foo2 = mod.attr("wrapper_foo")(1,3);
foo2.attr("_done") = true; // nonetype has no attribute _done error
// some other code
return bar_object;
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)