Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'output': 0.05; '[1,': 0.09; 'lawrence': 0.09; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'whichever': 0.09; 'python': 0.11; 'def': 0.12; 'language.': 0.14; "wouldn't": 0.14; 'arrived': 0.16; 'cease': 0.16; 'exists,': 0.16; 'link,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'troll': 0.16; 'url:general': 0.16; 'url:gmane': 0.16; 'subject:python': 0.16; 'language': 0.16; 'wrote:': 0.18; 'first.': 0.19; 'example': 0.22; 'header:User-Agent:1': 0.23; 'planet': 0.24; 'world,': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'probably': 0.32; 'thanks!': 0.32; 'url:python': 0.33; 'ago': 0.33; 'could': 0.34; 'knows': 0.35; 'something': 0.35; "who's": 0.35; 'thanks': 0.36; 'url:org': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'days': 0.60; 'most': 0.60; 'first': 0.61; 'back': 0.62; 'our': 0.64; 'charset:windows-1252': 0.65; 'here': 0.66; 'believe': 0.68; 'six': 0.68; 'url:me': 0.69; 'saw': 0.77; 'loose': 0.84; 'zen': 0.84; 'received:89': 0.85; 'url:comments': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: a python pitfall Date: Thu, 14 May 2015 21:12:35 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-89-240-161-222.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431634364 news.xs4all.nl 2884 [2001:888:2000:d::a6]:43584 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90631 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