Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.07; 'defaults': 0.07; 'none,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:None': 0.09; 'subject:Why': 0.09; 'adam': 0.16; 'iterable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:argparse': 0.16; 'used:': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'bit': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; "i've": 0.25; 'header:X -Complaints-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'trouble': 0.34; 'but': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'more': 0.64; 'batchelder': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Why does argparse return None instead of [] if an append action isn't used? Date: Mon, 26 Jan 2015 15:04:51 +0100 Organization: None References: <8tshpbxjvv.ln2@news.ducksburg.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdbf3f.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422281105 news.xs4all.nl 2829 [2001:888:2000:d::a6]:48842 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 3577457265 X-Received-Bytes: 3237 Xref: csiph.com comp.lang.python:84600 Adam Funk wrote: > On 2015-01-09, Ned Batchelder wrote: > >> On 1/9/15 9:44 AM, Adam Funk wrote: >>> This makes it a bit more trouble to use: >>> >>> if options.bar: >>> for b in options:bar >>> do_stuff(b) >>> >>> instead of >>> >>> for b in options.bar >>> do_stuff(b) >> >> This doesn't answer why the value defaults to None, and some people may >> recoil at it, but I've used: >> >> for b in options.bar or (): >> do_stuff(b) > > Do you mean "for b in options.bar or []:" ? Doesn't matter; in the context of a for loop any empty iterable would do.