Nothing in argparse is meant for this.
For what it's worth, parser starts with two groups of arguments, one of which is displayed as positionals , and the other as optionals (I forget the exact headers). So in your example there will actually be 4 groups.
The parser only uses argument groups when formatting help. For parsing, all arguments are placed in the main parser._actions list. And during parsing, the parser skips only one namespace object.
You can define individual parsers with different sets of arguments and call each one with parse_known_args . This works better with optionals arguments (marked) than with positionals . And it fragments your help.
I have studied in other SO questions a new Namespace class that could insert values ββbased on some point dest (names like group1.optA , group2.optC , etc.). I donβt remember whether I need to configure Action classes or not.
The main point is that when you save the value in the namespace, the parser or actually the Action object (argument) does:
setattr(namespace, dest, value)
This (and getattr / hasattr) is all that the Namespace parser expects. By default, the Namespace class is simple, slightly larger than a simple subclass of object . But it can be more complicated.
source share