classification
Title: Describe use of args parameter of argparse.ArgumentParser.parse_args
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, bethard, docs@python, paul.j3, r.david.murray, v+python
Priority: normal Keywords: patch

Created on 2012-07-22 22:12 by bethard, last changed 2017-09-10 05:57 by Mariatta. This issue is now closed.

Files
File name Uploaded Description Edit
remainder.patch paul.j3, 2013-04-03 06:44 review
remainder.patch paul.j3, 2013-04-03 07:18 review
Pull Requests
URL Status Linked Edit
PR 3292 merged r.david.murray, 2017-09-04 19:14
PR 3328 merged r.david.murray, 2017-09-04 23:21
PR 3325 merged r.david.murray, 2017-09-04 23:22
Messages (7)
msg166174 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2012-07-22 22:12
From http://bugs.python.org/issue14191#msg155202:

ArgumentParser.parse_args(args=None, namespace=None)
...
However, nowhere is the args= parameter explained.  One example is given at the end of 15.4.4.6 showing the use of args= which apparently accepts a list of parameters, similar to the positional list of parameters that are used in all the other examples.  It might be nice to clarify that.
msg185888 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2013-04-03 04:47
The 'args=' parameter is the same as the first positional parameter used in most of the examples.  That is normal Python behavior.

15.4.4.5. Beyond sys.argv
explains this alternative way of specifying argv.

Still 2 bullet points could be added to 15.4.4.

- args - A list of strings, default is sys.argv[1:] (link to 15.4.4.5.)
- namespace - A Namespace object, default is a new Namespace (link to 15.4.4.6.)

Maybe a 15.4.4.5. example using args=['1', '2', '3', '4'] would also be helpful.
msg185893 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2013-04-03 06:44
This patch to argparse.rst adds the argument points to parse_args().  

It also adds two points to the 'Upgrading optparse code' section, one about using 'nargs=argparse.REMAINDER', and other about 'parse_known_args()'.

I'm not entirely happy with the format of the internal hyperlinks.
msg185895 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2013-04-03 07:18
I changed the reference to the optparse allow_interspersed_args attribute to the disable_interspersed_args() method.
msg187330 - (view) Author: Glenn Linderman (v+python) * Date: 2013-04-19 01:50
These docs changes seem reasonable, from a side-by-side view (I didn't attempt to look at the formatted results of applying the patch), to better document the current behavior.
msg301243 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-09-04 19:17
I've turned this into a PR.  The example was already changed in a previous checkin.  I reworded the optparse porting addition to match the existing style of the list.
msg301800 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-09-10 05:57
Thanks, David. I merged the backport PRs. Closing this.
History
Date User Action Args
2017-09-10 05:57:04Mariattasetstatus: open -> closed

nosy: + Mariatta
messages: + msg301800

resolution: fixed
stage: resolved
2017-09-04 23:22:41r.david.murraysetpull_requests: + pull_request3350
2017-09-04 23:21:46r.david.murraysetpull_requests: + pull_request3348
2017-09-04 19:18:05r.david.murraysetversions: + Python 3.6, Python 3.7, - Python 3.2, Python 3.3, Python 3.4
2017-09-04 19:17:36r.david.murraysetnosy: + r.david.murray
messages: + msg301243
2017-09-04 19:14:33r.david.murraysetpull_requests: + pull_request3327
2013-04-19 01:50:35v+pythonsetnosy: + v+python
messages: + msg187330
2013-04-03 07:18:43paul.j3setfiles: + remainder.patch

messages: + msg185895
2013-04-03 06:44:01paul.j3setfiles: + remainder.patch
keywords: + patch
messages: + msg185893
2013-04-03 04:47:45paul.j3setnosy: + paul.j3
messages: + msg185888
2012-07-22 22:12:33bethardcreate