Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add explanation in the documentation
  • Loading branch information
ppaez committed Nov 23, 2022
commit a2687c655572e154d7e42ac7ad5e6602f4e3feb5
11 changes: 7 additions & 4 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1852,10 +1852,13 @@ Sub-commands
>>> parser.parse_args(['co', 'bar'])
Namespace(foo='bar')

One particularly effective way of handling sub-commands is to combine the use
of the :meth:`add_subparsers` method with calls to :meth:`set_defaults` so
that each subparser knows which Python function it should execute. For
example::
One particularly effective way of handling sub-commands is to
combine the use of the :meth:`add_subparsers` method with calls to
:meth:`set_defaults` so that each subparser knows which Python
function it should execute. The :meth:`set_defaults` method of the
Comment on lines +1855 to +1858
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend keeping the original structure so just the new changes can be more easily reviewed.

Suggested change
One particularly effective way of handling sub-commands is to
combine the use of the :meth:`add_subparsers` method with calls to
:meth:`set_defaults` so that each subparser knows which Python
function it should execute. The :meth:`set_defaults` method of the
One particularly effective way of handling sub-commands is to combine the use
of the :meth:`add_subparsers` method with calls to :meth:`set_defaults` so
that each subparser knows which Python function it should execute.
The :meth:`set_defaults` method of the

main parser is called to handle the case when no subcommand is
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit, since 'sub-command' was used above in the same paragraph

Suggested change
main parser is called to handle the case when no subcommand is
main parser is called to handle the case when no sub-command is

included in the command line. The main parser :meth:`print_help`
method is called to display the help in this case. For example::

>>> # sub-command functions
>>> def foo(args):
Expand Down