2012-04-05 8 views
1

내 프로젝트의 일부, 특히 Python/C++ 인터페이스를 리펙토링하려고합니다. 자신의 클래스에 그 인수 분해 한 후, 나는Boost :: Python Forward boost :: python :: object throwing 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

아! 고쳤다.

globals = main_method.attr("__dict__"); 

완벽 명백한 보인다, 다시 찾고, 그러나 적어도 나는 '년후 알고

대신 할당 연산자를 사용하여

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

에서 생성자에서 전역에 전화를 변경 유일한 사람은 나를 파멸시키는 사람이 없다는 판단에 비틀 거리고 말았다.

관련 문제