Re: Semi-newbie, rolling my own __deepcopy__

2005-04-27 Thread [EMAIL PROTECTED]
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 "**" nota

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-23 Thread [EMAIL PROTECTED]
Michael Spencer wrote: > [EMAIL PROTECTED] wrote: > > I'm back... > [wondering why copy.deepcopy barfs on array instances] > > > > http://www.python.org/doc/2.3.3/lib/module-copy.html > deepcopy: > ... > This version does not copy types like module, class, function, method, stack > trace, stack fra

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-21 Thread Michael Spencer
Michael Spencer wrote: http://www.python.org/doc/2.3.3/lib/module-copy.html deepcopy: ... This version does not copy types like module, class, function, method, stack trace, stack frame, file, socket, window, *array*, or any similar types. ... On reflection, I realize that this says that the arr

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-21 Thread Michael Spencer
[EMAIL PROTECTED] wrote: I'm back... [wondering why copy.deepcopy barfs on array instances] http://www.python.org/doc/2.3.3/lib/module-copy.html deepcopy: ... This version does not copy types like module, class, function, method, stack trace, stack frame, file, socket, window, *array*, or any sim

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-21 Thread [EMAIL PROTECTED]
I'm back... Thanks to Michael Spencer and Steven Bethard for their excellent help. It has taken me a few sessions of reading, and programming, and I've had to pick up the exploded fragments of my skull from time to time. But I now have succeeded in making deepcopy work for a simple class that I wr

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Steven Bethard
Michael Spencer wrote: BTW, as I mentioned in a previous comment, I believe this would be more plainly written as type(self).__new__(), to emphasize that you are constructing the object without initializing it. (There is a explanation of __new__'s behaviour at http://www.python.org/2.2/descrin

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote: ... I see Steve Bethard has answered most of the points in your last eMail On line 11 we create a dictionary item in memo, [id(self):type(self)]...So now I'm confused as to the purpose of memo. Why should it contain the ID of the *original* object? No, you create memo[id(s

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Michael Spencer wrote: [EMAIL PROTECTED] wrote: [snip] Anyway, my present problem is that I want to make copies of instances of my own custom classes. I'm having a little trouble understanding the process. Not that I think that it matters -- but in case it does, I'll tell

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread [EMAIL PROTECTED]
Michael Spencer wrote: > [EMAIL PROTECTED] wrote: [snip] > > Anyway, my present problem is that I want to make copies of instances > > of my own custom classes. I'm having a little trouble understanding > > the process. Not that I think that it matters -- but in case it does, > > I'll tell you th

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-04 Thread Michael Spencer
Steven Bethard wrote: Michael Spencer wrote: def __deepcopy__(self, memo={}): from copy import deepcopy result = self.__class__() memo[id(self)] = result result.__init__(deepcopy(tuple(self), memo)) return result I know this is not your recipe, but is th

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-04 Thread Steven Bethard
Michael Spencer wrote: def __deepcopy__(self, memo={}): from copy import deepcopy result = self.__class__() memo[id(self)] = result result.__init__(deepcopy(tuple(self), memo)) return result I know this is not your recipe, but is there any reason to use

Re: Semi-newbie, rolling my own __deepcopy__

2005-04-04 Thread Michael Spencer
[EMAIL PROTECTED] wrote: Hi, folks, First, the obligatory cheerleading -- then, my questions... I love Python! I am only an occasional programmer. Still, the logic of the language is clear enough that I can retain pretty much all that I have learned from one infrequent programming session to the

Semi-newbie, rolling my own __deepcopy__

2005-04-04 Thread [EMAIL PROTECTED]
Hi, folks, First, the obligatory cheerleading -- then, my questions... I love Python! I am only an occasional programmer. Still, the logic of the language is clear enough that I can retain pretty much all that I have learned from one infrequent programming session to the next. That's quite an a