0

I was going through some argparse code when I saw this. I have used argparse to create command line tools in the past but never came across this. I cannot find its documentation either.

What are action groups and why do we use them?

parser = argparse.ArgumentParser()
parser._action_groups.pop() 
0Nicholas
  • 389
  • 7
  • 16
  • They seem to be the implementation of [argument groups](https://docs.python.org/3/library/argparse.html#argument-groups) – Jan Wilamowski Jul 14 '21 at 03:14
  • 1
    Anything prefixed with `_` in `argparse` is not meant as public API, even if it may be accessed. See [this question](https://stackoverflow.com/questions/53327091/python-argparse-grouping-parent-parser-arguments-into-groups) for what this might do. – metatoaster Jul 14 '21 at 03:15
  • Note the `_` prefix; it's an undocumented implementation detail that you shouldn't use directly. – chepner Jul 14 '21 at 03:15
  • 1
    `format_help` passes these groups to the `HelpFormater` for display purposes. The list starts with 2 groups, `postional` and `optionals`, and `add_action_group` can create more. Every `Action` (created by `add_argument`) belongs to a group. They are not used for parsing, just help. – hpaulj Jul 14 '21 at 03:22

0 Answers0