<html>
<body>
Hello again list. I'm back in the boost.python game after a number of
months off, this time on Win XP.<br><br>
I want to be able to create Python instances from C++. These Python
instances hold wrapped C++ instances that I want to extract. For example,
I have a class called SomeObject that holds a wrapped C++ class called
MyPoint which is it's location onscreen. MyPoint is a class holding a
double for both x and y. Here's the Python code:<br><br>
<br>
<font face="Arial, Helvetica">import
JimsModule<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>#where
the wrapped MyPoint is<br><br>
class SomeObject:<br><br>
&nbsp;&nbsp;&nbsp; def __init__(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.location =
JimsModule.MyPoint( 3.2, -4.7 )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; def getPt(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.location<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; def getX(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
self.location.x<br><br>
<br>
In C++ I have the following:<br><br>
handle&lt;&gt;<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>(PyImport_ImportModule(
&quot;SomeObject&quot; )
);<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>//<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>SomeObject
class is in SomeObject.py module<br>
handle&lt;&gt;<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>module(
borrowed( PyImport_AddModule( &quot;SomeObject&quot; ) ) );<br>
handle&lt;&gt;<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>the_namespace(borrowed(
PyModule_GetDict(module.get()) ));<br>
object<x-tab>&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>the_class(
borrowed( PyDict_GetItemString(the_namespace.get(),
&quot;SomeObject&quot;) ));<br><br>
object&nbsp; obj = the_class();<br>
double<x-tab>&nbsp;&nbsp;</x-tab> x = call_method&lt;double&gt;(
obj.ptr(), &quot;getX&quot; );<x-tab>&nbsp;&nbsp;</x-tab>// returns 3.2
as it should.<br><br>
handle&lt;&gt; a( PyObject_CallMethod( obj.ptr(), &quot;getX&quot;, NULL
) );<br>
</font><font face="Arial, Helvetica" color="#0000FF">double</font><font face="Arial, Helvetica">&nbsp;
val =
extract&lt;</font><font face="Arial, Helvetica" color="#0000FF">double</font><font face="Arial, Helvetica">&gt;(
a.get()
);<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>//
Also returns 3.2<br><br>
I can extract POD fine. But what about getting my C++ MyPoint object
out?<br><br>
handle&lt;&gt; h( PyObject_CallMethod( obj.ptr(), &quot;getPt&quot;, NULL
) );<br>
MyPoint&amp; pt = extract&lt;MyPoint&amp;&gt;( h.get() );<br><br>
This throws an exception saying &quot;TypeError: No registered converter
was able to extract a C++ reference to type class MyPoint from this
Python object of type MyPoint&quot;. Obviously I am doing something
wrong, but I haven't a clue what.The PyObject* returned from
PyObject_CallMethod is OK if I print it out. But extracting the C++
object throws. I tried extracting a MyPoint object and a MyPoint* with
similar results.<br><br>
How can I pull my C++ object out of the Python object?<br><br>
-jim</font></body>
<br>
</html>