Semi-newbie, rolling my own __deepcopy__

ladasky at my-deja.com ladasky at my-deja.com
Wed Apr 27 03:42:13 EDT 2005


Michael Spencer wrote:
> It appears that if you want to deepcopy an object that may contain
arrays,
> you're going to have to 'roll your own' deep copier.  Something like
this
> would do it:

[method deleted]

Whew!  Michael, that was way more than I bargained for.  New issues for
me: the "**" notation, and the __repr__ method.  I'll have a look at
this -- but meanwhile, I converted my arrays over to lists.  My program
is now working.  Although it's a bit slower than it would be with
arrays, I'll live with the performance hit for now, because I can do
the deepcopy operation without further fuss.

> BTW: are you sure you really need to copy those arrays?

Yes, I do.  The arrays (now lists) contain the weights for a customized
neural net class that I wrote.  The process of evolving the neural nets
is to mutate copies of them.  I want to keep the original nets until
I'm sure I want to discard them, so copying is required.

--
Rainforest laid low.
"Wake up and smell the ozone,"
Says man with chainsaw.
John J. Ladasky Jr., Ph.D.




More information about the Python-list mailing list