From herron at ELLINGTON.com Tue Jul 7 01:04:44 2020 From: herron at ELLINGTON.com (Liam Herron) Date: Tue, 7 Jul 2020 05:04:44 +0000 Subject: [C++-sig] What is the best way to have a C++ function return a python datetime.date object or a python datetime.datetime object? Message-ID: <96426055F003C542B3FB8A0928736DF904F4FB8103@EX2.ELLINGTON.com> I have a date and a datetime object in C++ and I would like to add the following methods: toPyDate() toPyDatetime() fromPyDate() fromPyDatetime() I would like to 'bolt-on' these methods to my C++ classes in the BOOST_PYTHON_MODULE interface layer. I am trying to avoid additional python wrappers around my boost python library. Can this be done without additional python? What is the best/cleanest way to do this? Regards, Liam Herron ============================================================================================= Email transmissions can not be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of email transmission. In addition, the information contained in this email message is intended only for use of the individual or entity named above. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution,or copying of this communication, disclosure of the parties to it, or any action taken or omitted to be taken in reliance on it, is strictly prohibited, and may be unlawful. If you are not the intended recipient please delete this email message. ============================================================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From Holger.Joukl at LBBW.de Tue Jul 7 03:29:23 2020 From: Holger.Joukl at LBBW.de (Holger.Joukl at LBBW.de) Date: Tue, 7 Jul 2020 07:29:23 +0000 Subject: [C++-sig] What is the best way to have a C++ function return a python datetime.date object or a python datetime.datetime object? In-Reply-To: <96426055F003C542B3FB8A0928736DF904F4FB8103@EX2.ELLINGTON.com> References: <96426055F003C542B3FB8A0928736DF904F4FB8103@EX2.ELLINGTON.com> Message-ID: <2bd40ed69d2c421cbd969013d74ef05a@LBBW.de> Hi, > I have a date and a datetime object in C++ and I would like to add the following methods: > toPyDate() > toPyDatetime() > fromPyDate() > fromPyDatetime() > > I would like to ?bolt-on? these methods to my C++ classes in the BOOST_PYTHON_MODULE interface layer. > > I am trying to avoid additional python wrappers around my boost python library. > > Can this be done without additional python? What is the best/cleanest way to do this? Without having tried it: You should probably look at the Python datetime C-API and use it to construct DateTime objects, then return these from your methods: https://docs.python.org/3/c-api/datetime.html Returning PyObjects should allow boost.python to work its magic. The alternative being auto-magic conversion between your C++ date/time classes and Python DateTime objects, e.g. along the lines of https://www.boost.org/doc/libs/1_73_0/libs/python/doc/html/faq/how_can_i_automatically_convert_.html https://stackoverflow.com/a/16109416 Best regards, Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart HRA 4356, HRA 104 440 Amtsgericht Mannheim HRA 40687 Amtsgericht Mainz Die LBBW verarbeitet gemaess Erfordernissen der DSGVO Ihre personenbezogenen Daten. Informationen finden Sie unter https://www.lbbw.de/datenschutz.