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


Groups > comp.lang.python > #84606

Re: Why does argparse return None instead of [] if an append action isn't used?

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 <ian.g.kelly@gmail.com>
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 <ta4ipbx9j3.ln2@news.ducksburg.com>
References <l265obxc6d.ln2@news.ducksburg.com> <mailman.17529.1420816664.18130.python-list@python.org> <8tshpbxjvv.ln2@news.ducksburg.com> <mailman.18148.1422281105.18130.python-list@python.org> <ta4ipbx9j3.ln2@news.ducksburg.com>
From Ian Kelly <ian.g.kelly@gmail.com>
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 <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18151.1422288861.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Jan 26, 2015 at 8:50 AM, Adam Funk <a24061@ducksburg.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 14:44 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Skip Montanaro <skip.montanaro@gmail.com> - 2015-01-09 08:57 -0600
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 15:25 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Ned Batchelder <ned@nedbatchelder.com> - 2015-01-09 10:12 -0500
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000
      Re: Why does argparse return None instead of [] if an append action isn't used? Peter Otten <__peter__@web.de> - 2015-01-26 15:04 +0100
        Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 15:50 +0000
          Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 09:13 -0700
            Re: Why does argparse return None instead of [] if an append action isn't used? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-26 18:29 +0200
              Re: Why does argparse return None instead of [] if an append action isn't used? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-26 17:18 +0000
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:23 -0700
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:26 -0700
  Re: Why does argparse return None instead of [] if an append action isn't used? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-01-09 16:50 +0100
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000

csiph-web