From fghoussen at gmail.com Wed Jan 29 16:01:34 2020 From: fghoussen at gmail.com (HOUSSEN Franck) Date: Wed, 29 Jan 2020 22:01:34 +0100 Subject: [C++-sig] With boost python tuple, how to loop over tuple items? Message-ID: With boost python tuple, how to loop over tuple items? In dummy.cpp attached, I'd like to get line 8 to work. Afterwards, I noticed line 7 does not even compile. How to get the length of a tuple (line 8), and, why there could be some ambiguity (line 7). Any help / clue is appreciated. Franck -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Makefile Type: application/octet-stream Size: 98 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: dummy.cpp Type: text/x-c++src Size: 442 bytes Desc: not available URL: From torrin.jones at baesystems.com Thu Jan 30 09:39:03 2020 From: torrin.jones at baesystems.com (Jones, Torrin A (US)) Date: Thu, 30 Jan 2020 14:39:03 +0000 Subject: [C++-sig] With boost python tuple, how to loop over tuple items? In-Reply-To: Message-ID: <487jgm21p9znWqS@mail.python.org> If I remember correctly there is a len() function on the boost::python::object class. len() is documented at the bottom of this page . . . https://www.boost.org/doc/libs/1_66_0/libs/python/doc/html/reference/object_wrappers/boost_python_object_hpp.html I can?t help with the ambiguity. From: Cplusplus-sig On Behalf Of HOUSSEN Franck Sent: Wednesday, January 29, 2020 1:02 PM To: cplusplus-sig at python.org Subject: [C++-sig] With boost python tuple, how to loop over tuple items? *** WARNING *** EXTERNAL EMAIL -- This message originates from outside our organization. With boost python tuple, how to loop over tuple items? In dummy.cpp attached, I'd like to get line 8 to work. Afterwards, I noticed line 7 does not even compile. How to get the length of a tuple (line 8), and, why there could be some ambiguity (line 7). Any help / clue is appreciated. Franck -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at seefeld.name Thu Jan 30 09:45:55 2020 From: stefan at seefeld.name (stefan) Date: Thu, 30 Jan 2020 09:45:55 -0500 Subject: [C++-sig] With boost python tuple, how to loop over tuple items? In-Reply-To: References: Message-ID: <679acdd7-2783-540b-21ef-a450468f2566@seefeld.name> On 2020-01-29 4:01 p.m., HOUSSEN Franck wrote: > > > With boost python tuple, how to loop over tuple items? In dummy.cpp > attached, I'd like to get line 8 to work. Afterwards, I noticed line > 7 does not even compile. How to get the length of a tuple (line 8), > and, why there could be some ambiguity (line 7). Any help / clue is > appreciated. > Hi Frank, there are a few minor issues with your code, let me address them one-by-one to allow you to compile and run your example: * you don't need to link your extension module with the Python library. Symbols from that library are provided by the interpreter itself. (You only need to link to that when you embed the interpreter into your C++ app.) * you should not call `Py_Initialize()` during your module's initialization. Again, that function only needs to be called when you embed (and initialize) the interpreter itself. * use `boost::python::len(t)` to report the length of your tuple * the call `t[0]` itself is fine, but please be aware that it returns a `boost::python::object` instance. You can convert to a (Python) string and then extract the C++ string from that using ??? std::string s = bpl::extract(bpl::str(t[0])); and print that. Hope this helps, Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.png Type: image/png Size: 1478 bytes Desc: not available URL: From fghoussen at gmail.com Thu Jan 30 15:25:44 2020 From: fghoussen at gmail.com (HOUSSEN Franck) Date: Thu, 30 Jan 2020 21:25:44 +0100 Subject: [C++-sig] With boost python tuple, how to loop over tuple items? In-Reply-To: <679acdd7-2783-540b-21ef-a450468f2566@seefeld.name> References: <679acdd7-2783-540b-21ef-a450468f2566@seefeld.name> Message-ID: This helps ! Got it to work ! Thanks guys. Code attached for people who could need it. Franck Le jeu. 30 janv. 2020 ? 15:46, stefan a ?crit : > > On 2020-01-29 4:01 p.m., HOUSSEN Franck wrote: > > With boost python tuple, how to loop over tuple items? In dummy.cpp > attached, I'd like to get line 8 to work. Afterwards, I noticed line 7 does > not even compile. How to get the length of a tuple (line 8), and, why there > could be some ambiguity (line 7). Any help / clue is appreciated. > > Hi Frank, > > there are a few minor issues with your code, let me address them > one-by-one to allow you to compile and run your example: > > * you don't need to link your extension module with the Python library. > Symbols from that library are provided by the interpreter itself. (You only > need to link to that when you embed the interpreter into your C++ app.) > > * you should not call `Py_Initialize()` during your module's > initialization. Again, that function only needs to be called when you embed > (and initialize) the interpreter itself. > > * use `boost::python::len(t)` to report the length of your tuple > > * the call `t[0]` itself is fine, but please be aware that it returns a > `boost::python::object` instance. You can convert to a (Python) string and > then extract the C++ string from that using > > std::string s = bpl::extract(bpl::str(t[0])); > > and print that. > > Hope this helps, > [image: Stefan] > > -- > > ...ich hab' noch einen Koffer in Berlin... > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -- Bonne journ?e, Franck HOUSSEN -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.png Type: image/png Size: 1478 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: dummy.cpp Type: text/x-c++src Size: 353 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Makefile Type: application/octet-stream Size: 86 bytes Desc: not available URL: