very strange problem in 2.4

Fredrik Lundh fredrik at pythonware.com
Sat Apr 8 02:30:41 EDT 2006


John Zenger wrote:

> Your list probably contains several references to the same object,
> instead of several different objects.  This happens often when you use a
> technique like:
>
> list = [ object ] * 100
>
> ..because although this does make copies when "object" is an integer, it
> just makes references in other cases.

it always creates new references.

the only thing that distinguishes immutable objects (like integers) from
mutable objects (like lists) is that integers don't have any methods that
let you modify their contents.

there's no "this object is mutable" flag inside the object, and there's no
code in the list multiply operation, or anywhere else, that looks for such
a flag.

</F>






More information about the Python-list mailing list