On 2006-11-08, Georg Brandl <[EMAIL PROTECTED]> wrote:
> Peter van Kampen schrieb:
>> On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>>> I've collected a bunch of list pydioms and other notes here:
>>>
>>>     http://effbot.org/zone/python-list.htm
>> 
>> """
>> A = B = [] # both names will point to the same list
>> """
>> 
>> I've been bitten by this once or twice in the past, but I have always
>> wondered what it was useful for? Can anybody enlighten me?
>
> Do you never have a situation where you want to assign the same value
> to two variables?

In the sense that I might want two empty lists or maybe 2 ints that
are initialised as 0 (zero). That's what I (incorrectly) thought A = B
= [] did.

> Or are you objecting to the fact that both names point to the same
> object?

I'm not objecting to anything, merely wondering when I could/should
use this idiom. There's a nice example in another response (self.items
= items = [])

> It couldn't be otherwise. Consider:
>
> X = []
> A = B = X
>
> What should this do? Copy "X" and assign one copy to A, one to B?

Ah yes, I see the error in my ways...I skipped the A = B part too
lightly.

Thanks,

PterK


-- 
Peter van Kampen
pterk -- at -- datatailors.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to