what does 'a=b=c=[]' do

Ian Kelly ian.g.kelly at gmail.com
Thu Dec 22 21:59:06 EST 2011


On Thu, Dec 22, 2011 at 7:10 PM, alex23 <wuwei23 at gmail.com> wrote:
> On Dec 22, 6:51 pm, Rolf Camps <r... at roce.be> wrote:
>> I'm afraid it's dangerous to encourage the use of '[]' as assignment to
>> a parameter in a function definition. If you use the function several
>> times 'default' always points to the same list.
>
> I appreciate the concern, but adding a default argument guard would
> not only obscure the code. It's irrelevant, as you recognise, because
> no matter what, it's going to make copies of the default argument.

It's only irrelevant in the immediate context of the code you posted.
But when Joe Novice sees your code and likes it and duplicates it a
million times without receiving any warning about it, he's eventually
going to write a function that modifies its default list argument, and
he'll be in for a nasty surprise when he does.



More information about the Python-list mailing list