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: 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: References: 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 To: Henry Leyh 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 > Yes, I was trying that and it sort of works with strings if I use somethi= ng sufficiently improbable like "__UNSELECTED__" as default. But it gets d= ifficult 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 no= t 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