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


Groups > comp.lang.python > #53374

Re: argparse - specify order of argument parsing?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'parameters': 0.04; 'defaults': 0.07; 'modified': 0.07; 'arguments': 0.09; 'expected.': 0.09; 'iterate': 0.09; 'overwrite': 0.09; 'parsed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:parsing': 0.09; 'jan': 0.12; 'alvarez': 0.16; 'command- line': 0.16; 'given,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'specifying': 0.16; 'subject:argparse': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'command': 0.22; 'header:User-Agent:1': 0.23; 'config': 0.24; 'specify': 0.24; 'script': 0.25; 'first,': 0.26; 'right.': 0.26; 'switch': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'file': 0.32; 'option': 0.32; 'there': 0.35; 'sequence': 0.36; 'subject:?': 0.36; 'should': 0.36; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'first': 0.61; 'forward': 0.65; 'eduardo': 0.84; 'order:': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: argparse - specify order of argument parsing?
Date Sat, 31 Aug 2013 14:13:17 -0400
References <slrnl248ua.4b8.!nospam!astrochelonian@hypnotoad.vtr.net>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
In-Reply-To <slrnl248ua.4b8.!nospam!astrochelonian@hypnotoad.vtr.net>
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.420.1377972816.19984.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377972816 news.xs4all.nl 15921 [2001:888:2000:d::a6]:59299
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53374

Show key headers only | View raw


On 8/31/2013 1:11 PM, Eduardo Alvarez wrote:
> When using argparse, is there a way to specify in what order arguments
> get parsed?

I expect argparse to forward iterate the sequence of arguments that it 
receives.

> I am writing a script whose parameters can be modified in
> the following order:
>
> Defaults -> config file -> command-line switches.
>
> However, I want to give the option of specifying a config file using a
> command line switch as well, so logically, that file should be parsed
> before any other arguments are applied. However, it seems that
> parse_args() parses arguments in the order they're given,

Right.

 > so if the
> config file switch is not given first, the config file will overwrite
> whatever was in the command-line switches, which should have higher
> priority.

So just document that a config file has to be given first to work as 
expected. Order dependence among arguments is common.

-- 
Terry Jan Reedy

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


Thread

argparse - specify order of argument parsing? Eduardo Alvarez <!nospam!astrochelonian@gmail.com> - 2013-08-31 13:11 -0400
  Re: argparse - specify order of argument parsing? Tim Chase <python.list@tim.thechases.com> - 2013-08-31 12:50 -0500
  Re: argparse - specify order of argument parsing? Terry Reedy <tjreedy@udel.edu> - 2013-08-31 14:13 -0400
  Re: argparse - specify order of argument parsing? Terry Reedy <tjreedy@udel.edu> - 2013-08-31 14:17 -0400
  Re: argparse - specify order of argument parsing? Peter Otten <__peter__@web.de> - 2013-09-01 08:53 +0200

csiph-web