What other languages use the same data model as Python?

Chris Angelico rosuav at gmail.com
Tue May 3 18:00:35 EDT 2011


On Wed, May 4, 2011 at 6:47 AM, Hans Georg Schaathun <hg at schaathun.net> wrote:
> This looks like plain old transmission by reference to me.
> I.e. the functions get a reference to an object and make any
> change to the object.

"Reference" being exactly what's passed around. There are now two
references to that object. Since names always contain references (not
objects), it's very easy to share mutable objects
(lists/dictionaries/etc). There's an easy way for a caller or callee
to guarantee that a mutable is safe - just slice it:

identify_call(my_list[:])

That gives the called function a shallow copy of the list, which it
can modify to its heart's content, but the original list isn't
changed. Callee can do the same, with an assignment command at the top
of the function (a_list=a_list[:]).

Chris Angelico



More information about the Python-list mailing list