surprising behavior of chained initializations

Eric Pettersen (pett@ucsf.edu)
Wed, 25 Jan 1995 23:16:25 GMT

I believe I understand the behavior of the following script, but I
don't like it:

>#!/usr/local/bin/python
>
>a = b = []
>
>a.append("x")
>b.append("y")
>
>print b

The output is "['x', 'y']". I think the naive observer would expect
"['y']" as the output. Shouldn't the left-hand sides of multiple
initializations get copies of the right-hand sides, instead of name aliases (or
whatever)?

--
Eric Pettersen              pett@cgl.ucsf.edu (NeXTmail capable)

These opinions are mine; get your own.