Re: [C++-sig] Copying objects derived in python from C++?
This could be connected to missing pickle support. I think copy.copy() essentially pickles/unpickles to make the copy. I'd think if you add pickle support to your class it will work. I'm not sure about the details. See the "pickle suite" docs (link on main Boost.Python page). Ralf ----- Original Message ---- From: Mark Williams <mark@image-engine.com> To: c++-sig@python.org Sent: Wednesday, June 6, 2007 1:35:26 PM Subject: [C++-sig] Copying objects derived in python from C++? d_copy = copy.copy(d) func(d_copy) ____________________________________________________________________________________ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/
Ralf W. Grosse-Kunstleve wrote:
This could be connected to missing pickle support. I think copy.copy() essentially pickles/unpickles to make the copy. I'd think if you add pickle support to your class it will work. I'm not sure about the details. See the "pickle suite" docs (link on main Boost.Python page). Ralf
Thanks, this certainly seems to be the case. If I add ".enable_pickling()" to my Base class definition, then the example I posted works as expected. However, if I then modify the Derived class constructor so that it takes an argument, e.g.: class Derived(Base): def __init__(self, arg): Base.__init__(self) d = Derived(None) func(d) d_copy = copy.copy(d) func(d_copy) I get an error such as: Traceback (most recent call last): File "test.py", line 20, in <module> d_copy = copy.copy(d) File "python2.5/copy.py", line 95, in copy return _reconstruct(x, rv, 0) File "python2.5/copy.py", line 322, in _reconstruct y = callable(*args) TypeError: __init__() takes exactly 2 arguments (1 given) Cheers, Mark
Am Donnerstag, 07. Juni 2007 02:48:34 schrieb Mark Williams:
Thanks, this certainly seems to be the case. If I add ".enable_pickling()" to my Base class definition, then the example I posted works as expected. However, if I then modify the Derived class constructor so that it takes an argument, e.g.:
[...] TypeError: __init__() takes exactly 2 arguments (1 given)
How about adding pickle functions (i.e. __getinitargs__) to Derived, then? -- Ciao, / / /--/ / / ANS
Hans Meine wrote:
Am Donnerstag, 07. Juni 2007 02:48:34 schrieb Mark Williams:
Thanks, this certainly seems to be the case. If I add ".enable_pickling()" to my Base class definition, then the example I posted works as expected. However, if I then modify the Derived class constructor so that it takes an argument, e.g.:
[...] TypeError: __init__() takes exactly 2 arguments (1 given)
How about adding pickle functions (i.e. __getinitargs__) to Derived, then?
Thanks. That was the missing step. Mark
participants (3)
-
Hans Meine -
Mark Williams -
Ralf W. Grosse-Kunstleve