me+python at modelnine.org
Tue May 2 22:52:56 CEST 2006
Am Dienstag 02 Mai 2006 22:39 schrieb Edward Elliott:
> Which raises an interesting parallel question: is there a way to clone an
> arbitrary object?
Yes, check the copy module.
copy.copy() does a shallow copy of the parameter, copy.deepcopy() a deep copy
of the parameter. For the difference between the two, check the manual.
(basically, a deep copy copies the whole object tree for container objects
such as lists/tuples/dicts/instances, a shallow copy copies only the topmost
> but not small ones:
> >>> a = 5
> >>> b = a + 0
> >>> id(a) == id(b)
What sense is there cloning integers/strings? Integer and string objects are
immutable in Python, so why'd you want to have different IDs for an object of
the same value? It's the value you're working with in a program, not the
objects ID. At least it should be, if you're truly intent on working with the
(pseudo-random) object-ID, something with your design is really, really
More information about the Python-list