Path: csiph.com!usenet.pasdenom.info!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'modify': 0.07; 'function,': 0.09; 'omit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'used.': 0.09; 'argument,': 0.16; 'code?': 0.16; 'gotcha.': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'bit': 0.19; 'code,': 0.22; 'looks': 0.24; 'pass': 0.26; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'leave': 0.29; 'is?': 0.30; 'up.': 0.33; 'used,': 0.33; 'problem.': 0.35; 'but': 0.35; 'thanks': 0.36; 'subject:?': 0.36; 'wrong': 0.37; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'more': 0.64; 'frank': 0.68; 'frequently': 0.68; 'default': 0.69; 'subject:this': 0.83; 'safe.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Is this unpythonic? Date: Fri, 8 May 2015 10:01:52 +0200 X-Gmane-NNTP-Posting-Host: 197.86.223.132 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431072121 news.xs4all.nl 2880 [2001:888:2000:d::a6]:40552 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90123 Hi all I have often read about the gotcha regarding 'mutable default arguments' that frequently trips people up. I use them from time to time, but I have never had a problem. I have just delved a bit deeper to see if I am skating on thin ice. AFAICT my usage is safe. If I use a list as an argument, I only use it to pass values *into* the function, but I never modify the list. So if I omit the argument, the original default empty list is used, otherwise the list that I pass in is used. However, every time I look at my own code, and I see "def x(y, z=[]): ....." it looks wrong because I have been conditioned to think of it as a gotcha. Would it be more pythonic to change them all to use the alternative "z=None", or is it ok to leave it as it is? Or to phrase it differently, how would an experienced pythonista react on seeing this when reviewing my code? Thanks Frank Millman