why extending copy.*
Chris Liechti
cliechti at gmx.net
Fri Jun 21 17:01:55 EDT 2002
Uwe Mayer <merkosh at hadiko.de> wrote in
news:MPG.177d438123ae240598968d at news.rz.uni-karlsruhe.de:
> hi,
>
> i need shallow and deep copies of objects and I found the copy module in
> the reference library which does quite a good job.
> however, they write that one could implement the copy protocol by
> extending/ overwriting the __copy__() and __deepcopy__() method.
>
> since __copy__() and __deepcopy__() already duplicate the instance
> dictionary, __deepcopy__() even recursively. For what reasons would I
> want to extend /overwrite the capabilities of __copy__() or __deepcopy__
> ()?
its important when you use external resources. e.g. a file descriptor can
be duplicated so that you can call close() on each file object (in a copied
object and in the original) without infuence on the other (i think, but
you'll get the point...)
or a connection to a DB could be opened on the copied object so that the
copy and the original do not interfere.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list