Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98374
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Random832 <random832@fastmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: argparse: use of double dash to separate options and positional arguments |
| Date | Fri, 06 Nov 2015 16:56:50 -0500 |
| Lines | 31 |
| Message-ID | <mailman.100.1446847059.16136.python-list@python.org> (permalink) |
| References | <20151106100743.GN3685@isis.luna> <n1i126$o2f$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| X-Trace | news.uni-berlin.de UXBS0AJ9X5I/p53WWTwmVALmLKlW/WLD2MtM3roH907g== |
| Cancel-Lock | sha1:BA3Kw1wtCi6hrjtVbBeXDfOxXR4= |
| 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; 'args': 0.04; 'caller': 0.07; 'convention.': 0.07; 'interpreted': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'script,': 0.09; 'second.': 0.09; 'terminator': 0.09; 'python': 0.10; 'argument': 0.15; "(it's": 0.16; 'argument.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'ssh,': 0.16; 'subject:argparse': 0.16; 'subject:options': 0.16; 'shell': 0.18; 'arguments': 0.22; 'setup,': 0.22; 'pass': 0.22; 'script': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'processed': 0.27; 'said,': 0.27; 'arguments,': 0.29; "i'm": 0.30; 'another': 0.32; 'options': 0.33; 'foo': 0.33; 'received:comcast.net': 0.33; 'skip:- 10': 0.34; 'list': 0.34; 'attempt': 0.35; 'subject:use': 0.35; 'something': 0.35; 'skip:p 30': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'say': 0.37; 'received:org': 0.37; 'list.': 0.37; 'delete': 0.38; 'skip:p 20': 0.38; 'files': 0.38; 'sure': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'as:': 0.79; 'one;': 0.84; 'otten': 0.84; 'safer': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | c-68-39-146-59.hsd1.in.comcast.net |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Xref | csiph.com comp.lang.python:98374 |
Show key headers only | View raw
Peter Otten <__peter__@web.de> writes:
> I'm not sure about this one; one purpose of REMAINDER is to pass on the
> unprocessed arguments to another program/script, and this might follow the
> same convention. Should
>
> parser.add_argument('-v', '--verbose', action='store_true')
> parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
> args = parser.parse_args()
> subprocess.call(["rm"] + args.cmd_args)
>
> $ my_prog -v -- -r foo
>
> attempt to delete two files "-r" and "foo" or remove the "foo" directory?
> The first is the safer alternative, and as you say stripping the "--" is
> easy.
I think it should be the second. If the caller wants it to be treated as
a list of files rather than a list of arguments, it should be using
subprocess.call(["rm", "--"] + args.cmd_args).
The purpose is, as you said, to pass the *unprocessed* argument. -- has
been processed by being interpreted as a terminator for the argument
list.
I have a script (it's a shell script, not a python script) where I
actually do something similar... it does some setup, then calls ssh. If
I want to pass some options directly to ssh, I call it as:
"scriptname -script-option -- -ssh-option remote-command"
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: argparse: use of double dash to separate options and positional arguments Random832 <random832@fastmail.com> - 2015-11-06 16:56 -0500
csiph-web