Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90631 > unrolled thread

Re: a python pitfall

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2015-05-14 21:12 +0100
Last post2015-05-14 21:12 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: a python pitfall Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-14 21:12 +0100

#90631 — Re: a python pitfall

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-05-14 21:12 +0100
SubjectRe: a python pitfall
Message-ID<mailman.18.1431634364.17265.python-list@python.org>
On 14/05/2015 19:06, Billy Earney wrote:
> Hello friends:
>
> I saw the following example at
> http://nafiulis.me/potential-pythonic-pitfalls.html#using-mutable-default-arguments

Thanks for this link, the title "Engineering Fantasy" could have been 
made for the troll who's just arrived back here after a couple of years 
being absent.

> and
> did not believe the output produced and had to try it for myself....
>
> def foo(a,b,c=[]):
>      c.append(a)
>      c.append(b)
>      print(c)
>
> foo(1,1)
> foo(1,1)
> foo(1,1)
>
> produces:
> [1, 1]
> [1, 1, 1, 1]
> [1, 1, 1, 1, 1, 1]
>
> One would expect the following output:
> [1, 1]
> [1, 1]
> [1, 1]
>

One wouldn't expect the above because one knows better :)  This comes up 
every few months, has probably come up every few months since Python was 
first let loose on the world, will probably keep coming up every few 
months, and will cease coming up when Python is no longer used as 
something better has taken its place or the planet no longer exists, 
whichever comes first.  The most recent I recall was just six days ago 
http://comments.gmane.org/gmane.comp.python.general/776290

> Doesn't this valid the zen of python: "Explicit is better than implicit."  ?
>
> Thanks!
> Billy
>

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web