Re: [Boost-users] array of strings in boost python
In article <87k64aad0w.fsf__22758.9953029112$1157972153$gmane $org@pereiro.luannocracy.com>, dave@boost-consulting.com says...
<ctrembla@pcigeomatics.com> writes:
Hi,
newbie in python and boost::python
Please post Boost.Python questions to the C++-sig: http://www.boost.org/more/mailing_lists.htm#cplussig
I have a method in c++ that returns a vector of strings, how can i expose this method in python, and how should i use it in python
Sorry to turn the question around on you, but how do you /want/ to be able to use it in Python? That will determine how you should expose it.
You might look into http://boost.org/libs/python/doc/v2/indexing.html#vector_indexing_suite_clas... to see if it meets your needs.
hi, i have exposed my c++ class using the python.boost BOOST_PYTHON_MODULE(pysession) { class_<Session> >("Session") .def("Connect" ,&Session::Connect) .def("Disconnect",&Session::Disconnect) .def("SaveSession",& Session::SaveSession) .def("SaveSessionAs", &Session ::SaveSessionAs) .def("DeleteSession", & Session::DeleteSession) .def("GetListOfServer",& Session ::GetListOfServer) ; class_<std::vector<std::string> >("STD_String") .def(vector_indexing_suite<std::vector<std::string> >()) ; } i have compiled and it generated my pyd now in python , this is were i'm stuck, i was able to retreive the iterator, how can i iterate and how can i retreive the string within the vector? oString = self.oLogin.GetListOfServer() i=0 oList = range(oString.__len__()) oIter = oString.__iter__() for i in oList: oIter = oIter.next() error log oIter = oIter.next() TypeError: No Python class registered for C++ class class std::basic_string<char ,struct std::char_traits<char>,class std::allocator<char> > thanks, charles.
participants (1)
-
ctremblaï¼ pcigeomatics.com