[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    [C++-sig] Python subclassing from C++
From:       "eric.frederich () siemens ! com" <eric ! frederich () siemens ! com>
Date:       2016-04-04 18:00:01
Message-ID: E6044A01E1F4C34482019F2682F5292D26F62596 () USLZUA0EM23MSX ! ww017 ! siemens ! net
[Download RAW message or body]

Hello,

I'd like to expose an std::map to Python.  I found a great example here:
https://sourceforge.net/p/cctbx/code/HEAD/tree/trunk/scitbx/stl/map_wrapper=
.h#l240

It implements a bunch of methods to make it act like a dict (hooray duck ty=
ping)
But I think it misses some like __eq__, __ne__, pop.

I think this could be done better by extending collections.MutableMapping.
This way you'd only have to implement the 5 abstract methods rather than th=
e 20 or so it currently does.
How can I do this?  Is it possible to define the parent class when creating=
 a Python class from C++ using boost::python::class_?

I haven't been able to find a way.

Thanks,
~Eric

This message and any attachments are solely for the use of intended recipie=
nts. The information contained herein may include trade secrets, protected =
health or personal information, privileged or otherwise confidential inform=
ation. Unauthorized review, forwarding, printing, copying, distributing, or=
 using such information is strictly prohibited and may be unlawful. If you =
are not an intended recipient, you are hereby notified that you received th=
is email in error, and that any review, dissemination, distribution or copy=
ing of this email and any attachment is strictly prohibited. If you have re=
ceived this email in error, please contact the sender and delete the messag=
e and any attachment from your system. Thank you for your cooperation

[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 \
2px solid; } --></style> </head>
<body>
<font face="Calibri" size="2"><span style="font-size:11pt;">
<div>Hello,</div>
<div>&nbsp;</div>
<div>I&#8217;d like to expose an std::map to Python.&nbsp; I found a great example \
here:</div> <div><a href="https://sourceforge.net/p/cctbx/code/HEAD/tree/trunk/scitbx/stl/map_wrapper.h#l240"><font \
color="blue"><u>https://sourceforge.net/p/cctbx/code/HEAD/tree/trunk/scitbx/stl/map_wrapper.h#l240</u></font></a></div>
 <div>&nbsp;</div>
<div>It implements a bunch of methods to make it act like a dict (hooray duck \
typing)</div> <div>But I think it misses some like __eq__, __ne__, pop.</div>
<div>&nbsp;</div>
<div>I think this could be done better by extending collections.MutableMapping.</div>
<div>This way you&#8217;d only have to implement the 5 abstract methods rather than \
the 20 or so it currently does.</div> <div>How can I do this?&nbsp; Is it possible to \
define the parent class when creating a Python class from C&#43;&#43; using \
boost::python::class_?</div> <div>&nbsp;</div>
<div>I haven&#8217;t been able to find a way.</div>
<div>&nbsp;</div>
<div>Thanks,</div>
<div>~Eric</div>
<div>&nbsp;</div>
<div><font face="Times New Roman" size="2"><span style="font-size:9pt;">This message \
and any attachments are solely for the use of intended recipients. The information \
contained herein may include trade secrets, protected health or personal information, \
privileged or otherwise confidential information. Unauthorized review, forwarding, \
printing, copying, distributing, or using such information is strictly prohibited and \
may be unlawful. If you are not an intended recipient, you are hereby notified that \
you received this email in error, and that any review, dissemination, distribution or \
copying of this email and any attachment is strictly prohibited. If you have received \
this email in error, please contact the sender and delete the message and any \
attachment from your system. Thank you for your cooperation</span></font></div>
</span></font>
</body>
</html>



_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig
--===============7636891221252666997==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic