[issue15427] Describe use of args parameter of argparse.ArgumentParser.parse_args
New submission from Steven Bethard <steven.bethard@gmail.com>:
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. ---------- assignee: docs@python components: Documentation messages: 166174 nosy: bethard, docs@python priority: normal severity: normal status: open title: Describe use of args parameter of argparse.ArgumentParser.parse_args type: behavior versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
paul j3 added the comment: 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. ---------- nosy: +paul.j3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
paul j3 added the comment: 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. ---------- keywords: +patch Added file: http://bugs.python.org/file29661/remainder.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
paul j3 added the comment: I changed the reference to the optparse allow_interspersed_args attribute to the disable_interspersed_args() method. ---------- Added file: http://bugs.python.org/file29662/remainder.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Glenn Linderman added the comment: 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. ---------- nosy: +v+python _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Changes by R. David Murray <rdmurray@bitdance.com>: ---------- pull_requests: +3327 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
R. David Murray added the comment: 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. ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Changes by R. David Murray <rdmurray@bitdance.com>: ---------- versions: +Python 3.6, Python 3.7 -Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Changes by R. David Murray <rdmurray@bitdance.com>: ---------- pull_requests: +3348 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Changes by R. David Murray <rdmurray@bitdance.com>: ---------- pull_requests: +3350 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15427> _______________________________________
Mariatta Wijaya added the comment: Thanks, David. I merged the backport PRs. Closing this. ---------- nosy: +Mariatta resolution: -> fixed stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue15427> _______________________________________
participants (5)
-
Glenn Linderman
-
Mariatta Wijaya
-
paul j3
-
R. David Murray
-
Steven Bethard