Michael Hudson wrote: > Simon Brunning <[EMAIL PROTECTED]> writes: > > >>I think that copy is very rarely used. I don't think I've ever imported it. >> >>Or is it just me? > > > Not really. I've used it once that I can recall, to copy a kind of > generic "default value", something like: > > def value(self, v, default): > if hasattr(source, v): return getattr(source, v) > else: return copy.copy(default) > > (except not quite, there would probably be better ways to write > exactly that). > > Cheers, > mwh
My most recent use of copy.deepcopy() was to save the state of a recusivly built object so that it could be restored before returning a result that involved making nested changes (with multiple methods) to the ojbects subparts as part of the result calculation. The alternative would be to use a flag and shallow copies in all the methods that altered the object. copy.deepcopy() was a lot easier as it's only needed in the method that initiates the result calculation. Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list