Method returning new instance of class?

Arthur ajsiegel at optonline.com
Sun Sep 5 09:53:35 EDT 2004


"Arthur" <ajsiegel at optonline.com> wrote in message
news:EMD_c.7014$Wv5.3607 at newsread3.news.atl.earthlink.net...
>
> Something like this seemed to work:
>
> def __copy__(self):
>    newcopy=copy.deepcopy(self)
>   newcopy.vpythonobject=<intialize new vpython object here>
>   return newcopy
>
> But before getting too far into testing whether this accomplished the copy
I
> was looking for (perhaps the success was more apparent than real, and the
> advice to resort to copy_reg is more unavoidable than I understand) I
> realized that I had misconceived something more fundamental.  That the
> normal instance creation process involves registerting the new instance
with
> the app in various ways, and that a copy won't accomplish this.
>
> That is until wrote the last paragraph, and realized that I might be able
to
> throw the registration routines into the __copy__ method.
>
> Hmmm.
>
> Let's try.

With the further realization that I wasn't buying myself anything in
particular by overriding __copy__ at this stage, but that some function
starting with a deepcopy and then reassigning some of the attributes derived
from VPython (which luckily are the attributes that I want as fresh for what
I am trying to do), then running through the "registration" routines
normally done on __init__, then returning the manipulated deepcopy - I seem
to be home.

Now on to the functionality I had in mind, given this capability.

Which should be fun.

Art





More information about the Python-list mailing list