homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: document argparse's nargs=REMAINDER
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: bethard, docs@python, eric.araujo, georg.brandl, python-dev, sandro.tosi, tshepang
Priority: normal Keywords:

Created on 2011年12月15日 13:28 by bethard, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (11)
msg149552 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011年12月15日 13:28
There is an undocumented value for add_argument's nargs parameter, REMAINDER, which can be used to consume all the remaining arguments. This is commonly useful for command line utilities that dispatch to other command line utilities.
Though undocumented, it has been used successfully by at least a few different people:
http://stackoverflow.com/questions/5826881/how-to-use-argparse-to-collect-arguments-for-a-separate-command-line-without
http://code.google.com/p/argparse/issues/detail?id=52
And I just received an email from yet another user who used it successfully.
So I think it's time to graduate this from a hidden feature to a real documented one.
msg151654 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年01月19日 21:03
New changeset 35665f6f3674 by Sandro Tosi in branch '2.7':
Issue #13605: add documentation for nargs=argparse.REMAINDER
http://hg.python.org/cpython/rev/35665f6f3674
New changeset 6f3d55f5a31e by Sandro Tosi in branch '3.2':
Issue #13605: add documentation for nargs=argparse.REMAINDER
http://hg.python.org/cpython/rev/6f3d55f5a31e
New changeset 6b4cec0719a3 by Sandro Tosi in branch 'default':
Issue #13605: merge with 3.2
http://hg.python.org/cpython/rev/6b4cec0719a3 
msg151655 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年01月19日 21:26
New changeset 1b481e76cd16 by Sandro Tosi in branch '2.7':
Issue #13605: more meaningful example + fixes
http://hg.python.org/cpython/rev/1b481e76cd16
New changeset d6e53d1f46eb by Sandro Tosi in branch '3.2':
Issue #13605: more meaningful example + fixes
http://hg.python.org/cpython/rev/d6e53d1f46eb
New changeset 4c3271527794 by Sandro Tosi in branch 'default':
Issue #13605: merge with 3.2
http://hg.python.org/cpython/rev/4c3271527794 
msg152511 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012年02月03日 13:58
It would be best if the 3.x docs did not use a print statement <wink>. The code block should also be preceded by ::.
msg153716 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年02月19日 18:59
New changeset 996efb0425c5 by Sandro Tosi in branch '3.2':
Issue #13605: use print() in argparse nargs example
http://hg.python.org/cpython/rev/996efb0425c5
New changeset c3daa6a834c6 by Sandro Tosi in branch 'default':
Issue #13605: merge with 3.2
http://hg.python.org/cpython/rev/c3daa6a834c6 
msg153745 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012年02月20日 00:52
I have added the missing "::" before code blocks (one was added by the patch you committed, others were already here).
I’m not entirely sure they are needed (Python code blocks seem to be autodetected and show up colorized too), but I did it for consistency (and to make my editor detect them).
msg153765 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2012年02月20日 07:14
On Mon, Feb 20, 2012 at 01:52, Éric Araujo <report@bugs.python.org> wrote:
> I’m not entirely sure they are needed (Python code blocks seem to be autodetected and show up colorized too), but I did it for consistency (and to make my editor detect them).
Yeah, I refrained to add them since the code blocks were already
correctly identified; but consistency is Good :)
msg153770 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012年02月20日 08:39
Blocks not introduced by "::" are *NOT* code blocks.
If they happen to begin with ">>> ", they are recognized as doctest blocks and colorized as doctests.
Doctest blocks shouldn't be indented. (The indent is a blockquote in this case.)
msg153773 - (view) Author: Tshepang Lekhonkhobe (tshepang) * Date: 2012年02月20日 10:26
(this is only concerning the latest commit)
Not sure if I should open a new issue, but why is there a print function at all, given that:
>>> print(parser.parse_args('--foo B cmd --arg1 XX ZZ'.split()))
Namespace(args=['--arg1', 'XX', 'ZZ'], command='cmd', foo='B')
>>> parser.parse_args('--foo B cmd --arg1 XX ZZ'.split())
Namespace(args=['--arg1', 'XX', 'ZZ'], command='cmd', foo='B')
msg153824 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012年02月21日 00:11
> Blocks not introduced by "::" are *NOT* code blocks.
> If they happen to begin with ">>> ", they are recognized as doctest blocks
> and colorized as doctests.
Ah, that’s it! Thanks. So we have two valid ways of marking up doctest-like blocks, "::" ° indent and implicit markup, right?
msg153851 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012年02月21日 06:17
Yes, that's correct.
History
Date User Action Args
2022年04月11日 14:57:24adminsetgithub: 57814
2012年02月21日 06:17:30georg.brandlsetmessages: + msg153851
2012年02月21日 00:11:59eric.araujosetmessages: + msg153824
2012年02月20日 10:26:24tshepangsetnosy: + tshepang
messages: + msg153773
2012年02月20日 08:39:09georg.brandlsetnosy: + georg.brandl
messages: + msg153770
2012年02月20日 07:14:24sandro.tosisetmessages: + msg153765
2012年02月20日 00:52:56eric.araujosetmessages: + msg153745
2012年02月19日 18:59:38python-devsetmessages: + msg153716
2012年02月03日 13:58:20eric.araujosetnosy: + eric.araujo
messages: + msg152511
2012年01月19日 21:26:26python-devsetmessages: + msg151655
2012年01月19日 21:09:23sandro.tosisetstatus: open -> closed
versions: + Python 2.7, Python 3.2
nosy: + sandro.tosi

resolution: fixed
stage: needs patch -> resolved
2012年01月19日 21:03:38python-devsetnosy: + python-dev
messages: + msg151654
2011年12月15日 13:28:29bethardcreate

AltStyle によって変換されたページ (->オリジナル) /