Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 37
    Do the ? and * mean the same thing they mean in regular expressions (i.e. ? requires 0 or 1, and * requiring 0 or more)? If so, does + work as well? Commented Jan 8, 2013 at 16:11
  • 58
    @dolan: Yes, + works, too. See docs.python.org/2/library/argparse.html#nargs for the details. Commented Jan 8, 2013 at 23:53
  • 4
    is there some way to get dir to show up in optional arguments? or it seems that positional arguments should have a preceeding 'optional' qualifier. is it possible to register (as far as help is concerned) it as such? Commented Sep 15, 2014 at 21:54
  • 6
    @ant From the above, you can see that dir is optional (that it appears in square brackets in argparse output indicates this). Commented Sep 15, 2014 at 22:00
  • 5
    Here's the updated (Python 3) documentation--a careful reading of it explains it all: docs.python.org/3/library/argparse.html#nargs. For anyone new to the argparse module, start with the tutorial: docs.python.org/3/howto/argparse.html Commented May 16, 2019 at 1:55