Re: Semi-newbie, rolling my own __deepcopy__
- From: Michael Spencer <mahs@xxxxxxxxxxxxxxxxx>
- Date: Mon, 04 Apr 2005 12:04:42 -0700
Steven Bethard wrote:
I don't know - aren't they identical? I would write self.__class__ (without claiming that that's better)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 self.__class__() instead of type(self)() if you know you're inside a new-style class?
STeVe
BTW, I had a different question about the method:
wouldn't:
result = self.__class__.__new__()
or in your form:
result = type(self).__new__()be better (i.e., clearer and possibly safer) than calling __init__ twice (but I haven't tried it!)
Michael
.
- References:
- Semi-newbie, rolling my own __deepcopy__
- From: ladasky@xxxxxxxxxxx
- Re: Semi-newbie, rolling my own __deepcopy__
- From: Michael Spencer
- Re: Semi-newbie, rolling my own __deepcopy__
- From: Steven Bethard
- Semi-newbie, rolling my own __deepcopy__
- Prev by Date: Re: help with python-devel!!!
- Next by Date: Re: How to reload local namespace definitions in the python interpreter?
- Previous by thread: Re: Semi-newbie, rolling my own __deepcopy__
- Next by thread: Re: Semi-newbie, rolling my own __deepcopy__
- Index(es):
Relevant Pages
|