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


Groups > comp.lang.python > #45343

Re: Determine actually given command line arguments

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@gmail.com>
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; 'anyway.': 0.05; 'say,': 0.05; 'initialize': 0.07; 'none,': 0.07; 'variables': 0.07; 'arguments': 0.09; 'default.': 0.09; 'processing,': 0.09; 'subject:command': 0.09; 'cc:addr:python-list': 0.11; 'arg': 0.16; 'boolean': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'sender:addr:gmail.com': 0.17; 'trying': 0.19; 'command': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'gets': 0.27; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'there.': 0.32; 'actual': 0.34; 'could': 0.34; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'rather': 0.38; 'even': 0.60; 'easy': 0.60; 'note:': 0.66; 'between': 0.67; 'default': 0.69; 'distinguish': 0.84; 'dude': 0.84; 'idiom': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=KWE7z5FbRITwWHe80ZxhHtKNHyxkJ2fsvmxWntyyYM8=; b=kPon/1g515z7J1/gu1ZVGqq5OuoZo+elUvTg5RTTyxMbGtKXPr+0ainMwDpl+o5Emf ufYUmeRzMy8wdDK3Q4e1kyeaW7Q1jiSIc5owm6LgMMrX4zvo0/R4H9Ma+5t6ATUbHFcW ViDv4zQzhS5Qw/8ptwKpiR/TfvFh62u1NQxEX8RL4TF+WHhQt+aJH0ivJa8mJsILIQIH bEx++jv17OHbaFvPqOuLiZdBip+Bvcsz0UDipMIMRYWkRRD4tkPA9ns8WETbn4LMJIFE GBiARs1s6IxcJZBCjd4rlfvN9VdLXvCvhNm1ziT4bpRx04GzM2nIOJZoYbZAgnSc9JW6 UCAg==
MIME-Version 1.0
X-Received by 10.50.45.230 with SMTP id q6mr5661210igm.39.1368626893034; Wed, 15 May 2013 07:08:13 -0700 (PDT)
Sender skip.montanaro@gmail.com
In-Reply-To <kn03rt$d74$1@gwdu112.gwdg.de>
References <kmva9j$1hbk$1@gwdu112.gwdg.de> <roy-C8F8F4.08245415052013@news.panix.com> <kn00fb$8kc$1@gwdu112.gwdg.de> <mailman.1697.1368622878.3114.python-list@python.org> <kn03rt$d74$1@gwdu112.gwdg.de>
Date Wed, 15 May 2013 09:08:12 -0500
X-Google-Sender-Auth 5gVLj5BQL69ZAuT4LDSJnC2kGU0
Subject Re: Determine actually given command line arguments
From Skip Montanaro <skip@pobox.com>
To Henry Leyh <henry.leyh@ipp.mpg.de>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1699.1368626900.3114.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368626900 news.xs4all.nl 16002 [2001:888:2000:d::a6]:43821
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45343

Show key headers only | View raw


> Yes, I was trying that and it sort of works with strings if I use something sufficiently improbable like "__UNSELECTED__" as default.  But it gets difficult with boolean or even number arguments where you just may not have valid "improbable" defaults.  You could now say, so what, it's the default anyway.  But in my program I would like to distinguish between given and not given arguments rather than between default and non-default.

Initialize all your arg variables to None, then after command line
processing, any which remain as None weren't set on the command line.
At that point, set them to the actual defaults.  I think that's a
pretty common idiom.

Note: I am an old cranky dude and still use getopt.  This idiom is
pretty easy there.  YMMV with argparse or optparse.

Skip

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


Thread

Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 08:34 +0200
  Re: Determine actually given command line arguments "Colin J. Williams" <cjw@ncf.ca> - 2013-05-15 08:03 -0400
    Re: Determine actually given command line arguments Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-15 15:51 +0300
  Re: Determine actually given command line arguments Roy Smith <roy@panix.com> - 2013-05-15 08:24 -0400
    Re: Determine actually given command line arguments Dave Angel <davea@davea.name> - 2013-05-15 08:51 -0400
    Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 14:52 +0200
      Re: Determine actually given command line arguments Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-05-15 14:00 +0100
        Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 15:50 +0200
          Re: Determine actually given command line arguments Skip Montanaro <skip@pobox.com> - 2013-05-15 09:08 -0500
            Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 16:39 +0200
              Re: Determine actually given command line arguments Skip Montanaro <skip@pobox.com> - 2013-05-15 09:51 -0500
          Re: Determine actually given command line arguments Wayne Werner <wayne@waynewerner.com> - 2013-05-15 09:16 -0500
      Re: Determine actually given command line arguments roy@panix.com (Roy Smith) - 2013-05-15 11:29 -0400
        Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-16 07:43 +0200
          Re: Determine actually given command line arguments Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-16 09:08 +0300
            Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-16 09:29 +0200

csiph-web