Re: Semi-newbie, rolling my own __deepcopy__
- From: Steven Bethard <steven.bethard@xxxxxxxxx>
- Date: Wed, 06 Apr 2005 12:28:42 -0600
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/descrintro.html#__new__).
There is also now documentation in the standard location:
http://docs.python.org/ref/customization.html
And just to clarify Michael's point here, writing this as __new__ means that __init__ is not called twice:
py> class C(object): .... def __new__(cls): .... print '__new__' .... return super(C, cls).__new__(cls) .... def __init__(self): .... print '__init__' .... py> c = C() __new__ __init__ py> c2 = type(c)(); c2.__init__() __new__ __init__ __init__ py> c3 = type(c).__new__(C); c3.__init__() __new__ __init__
But definitely check the docs for more information on __new__. Some of the interworkings are kind of subtle.
STeVe .
- 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: ladasky@xxxxxxxxxxx
- Re: Semi-newbie, rolling my own __deepcopy__
- From: Michael Spencer
- Semi-newbie, rolling my own __deepcopy__
- Prev by Date: Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control
- Next by Date: Compiling extensions
- Previous by thread: Re: Semi-newbie, rolling my own __deepcopy__
- Next by thread: Re: Semi-newbie, rolling my own __deepcopy__
- Index(es):
Relevant Pages
|
Loading