2012-04-05 4 views
1

私は私のプロジェクトの一部、特にPython/C++インターフェイスをリファクタリングしようとしています。 標準ブースト::のpythonのpythonの初期化が前に働いていた。しかし、それ自身のクラスにそれを因数分解した後、私はBoost :: Python Forward宣言boost :: python :: object throw python TypeError

TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies> 
を取得しています

boost::python::object main_module = boost::python::import("__main__"); 
boost::python::object globals(main_module.attr("__dict__")); 

// ...

以下のように、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> 

私が考えることができるのは、それを使用する前に「グローバル」を宣言することと関係があることだけです。この場合、私はこれを行うことができる別の方法がありますか?

答えて

0

Ah!修正しました。

globals(main_method.attr("__dict__")); 

から代わりに代入演算子を使用するコンストラクタでグローバルへの呼び出しを変更:

振り返る
globals = main_method.attr("__dict__"); 

、完全に明白なようだが、少なくとも私は「wasn知っています唯一の人は私を衰えさせる人がいないということで判断した。

関連する問題