Dictionary assignment

Terry Reedy tjreedy at udel.edu
Fri Aug 15 19:33:01 EDT 2003


"Mark Daley" <mark at diversiform.com> wrote in message
news:mailman.1060987824.17496.python-list at python.org...
> format[self.formats.get()][key] = current[key]

Above statement assumes 1) that current is a sequence or dict (or
instance simulating such) and that the object associated with key is
an index or key therein.  It retrieves the associated object.  It then
assumes 2) that format is a sequence or dict (according to whether
self.formats.get() returns an int index or dict key) of mutable
sequences or dicts (according to the nature of key).  After retrieving
the appropriate collection, it associates key with the
retrieved-from-current object in that collection.

> Now, all disgust from my example aside, shouldn't this line cause a
new key
> (whatever self.formats get() produces) whose contents are an exact
copy of
> current?

The only new 'thing' created is the association between key and
current[key] in format[self.formats.get()].  There are no new Python
objects created.

> BTW, I do this to avoid those location references.

No idea of what this means.

>  I need to get an actual copy

Of what?

> and this is the only way I can (currently) guarantee it.

Nope.  Assignment 'creates' bindings (of object to target), not
objects or copies thereof.

Terry J. Reedy






More information about the Python-list mailing list