Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4a.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'context': 0.07; 'purpose.': 0.07; 'subject:None': 0.09; 'subject:Why': 0.09; 'jan': 0.12; 'adam': 0.16; 'conveys': 0.16; 'iterable': 0.16; 'iterable,': 0.16; 'iterated': 0.16; 'singleton': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'do.': 0.18; '>>>': 0.22; 'mon,': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'generally': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'tuples': 0.31; 'this.': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'course': 0.61; 'more': 0.64; '26,': 0.68; '2015': 0.84; 'batchelder': 0.84; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=w5gIoSV4LViz2Q8jQbtlVwK5xa0WfobXEoDBVcaiRNo=; b=TjBSCifwPfZWrM7B1EkqGo/J0z+En8Nuo9E8NS3ZT/LXQQhRr9TkjyDh7AYANr63zn PHXcHkEZpcTf6QjSClAtcD3ooFkHGSpt65zVRfbQhvOiCyIW6QKlVhTomvlsDBXUdMMM o6kuDnomto93P2HLx58LZQm1Ckz4G7bvYvuD/fhRoGkxYRYtMr8as7SBhlivkgG7mlfS 384v+/MoufDsqzZZs3pcIroAyZgi2j+13Xx50jQ5vYC51anxkDrLxqTkWBzon5AfxHm6 /7DzenCZsghRIQdOFMoVd/uipRKtSdewogNQQsCxZIQ2pZsK1qsrSkaIXI9nRsgU4939 THBw== X-Received: by 10.68.221.165 with SMTP id qf5mr34849235pbc.101.1422288858950; Mon, 26 Jan 2015 08:14:18 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <8tshpbxjvv.ln2@news.ducksburg.com> From: Ian Kelly Date: Mon, 26 Jan 2015 09:13:38 -0700 Subject: Re: Why does argparse return None instead of [] if an append action isn't used? To: Python Content-Type: text/plain; charset=UTF-8 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422288861 news.xs4all.nl 2965 [2001:888:2000:d::a6]:52588 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84606 On Mon, Jan 26, 2015 at 8:50 AM, Adam Funk wrote: > On 2015-01-26, Peter Otten wrote: > >> Adam Funk wrote: >> >>> On 2015-01-09, Ned Batchelder wrote: >>>> 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. > > Of course it would. Doh! Stylistically, I generally prefer the empty list for this. The empty tuple might be a little faster since it's a singleton and doesn't need to be constructed at runtime, but that's clearly a micro-optimization, and I think the list more accurately conveys the intention of "something to be iterated over". Although tuples are iterable, I don't often use them for that purpose.