Based on the argparse library, this shouldn't happen :/
>>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('-g', '--global') _StoreAction(option_strings=['-g', '--global'], dest='global', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) >>> subparsers = parser.add_subparsers(dest="subparser_name") >>> foo_parser = subparsers.add_parser('foo') >>> foo_parser.add_argument('-g', '--global', dest='foo_global') _StoreAction(option_strings=['-g', '--global'], dest='foo_global', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) >>> foo_parser.add_argument('-c', '--count') _StoreAction(option_strings=['-c', '--count'], dest='count', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) >>> args = parser.parse_args(['-g', 'xyz', 'foo', '--count', '42']) >>> parser.parse_args(['-g', 'xyz', 'foo', '--count', '42']) Namespace(count='42', foo_global=None, global='xyz', subparser_name='foo') >>> parser.parse_args(['foo', '-g', 'xyz', '--count', '42']) Namespace(count='42', foo_global='xyz', global=None, subparser_name='foo') >>> parser.add_argument('--version', action='version', version='0.1') _VersionAction(option_strings=['--version'], dest='version', nargs=0, const=None, default='==SUPPRESS==', type=None, choices=None, help="show program's version number and exit", metavar=None) >>> foo_parser.add_argument('--version', dest='foo_version') _StoreAction(option_strings=['--version'], dest='foo_version', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) >>> parser.parse_args(['foo', '-g', 'xyz', '--count', '42', '--version', '2']) Namespace(count='42', foo_global='xyz', foo_version='2', global=None, subparser_name='foo') >>> parser.parse_args(['--version', '2', 'foo', '-g', 'xyz', '--count', '42']) 0.1
Based on the argparse library, this shouldn't happen :/
>>> import argparse ArgumentParser( ) add_argument( '-g', '--global') n(option_ strings= ['-g', '--global'], dest='global', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) add_subparsers( dest="subparser _name") add_parser( 'foo') add_argument( '-g', '--global', dest='foo_global') n(option_ strings= ['-g', '--global'], dest='foo_global', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) add_argument( '-c', '--count') n(option_ strings= ['-c', '--count'], dest='count', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) parse_args( ['-g', 'xyz', 'foo', '--count', '42']) parse_args( ['-g', 'xyz', 'foo', '--count', '42']) count=' 42', foo_global=None, global='xyz', subparser_ name='foo' ) parse_args( ['foo', '-g', 'xyz', '--count', '42']) count=' 42', foo_global='xyz', global=None, subparser_ name='foo' ) add_argument( '--version' , action='version', version='0.1') ion(option_ strings= ['--version' ], dest='version', nargs=0, const=None, default= '==SUPPRESS= =', type=None, choices=None, help="show program's version number and exit", metavar=None) add_argument( '--version' , dest='foo_version') n(option_ strings= ['--version' ], dest='foo_version', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) parse_args( ['foo', '-g', 'xyz', '--count', '42', '--version', '2']) count=' 42', foo_global='xyz', foo_version='2', global=None, subparser_ name='foo' ) parse_args( ['--version' , '2', 'foo', '-g', 'xyz', '--count', '42'])
>>> parser = argparse.
>>> parser.
_StoreActio
>>> subparsers = parser.
>>> foo_parser = subparsers.
>>> foo_parser.
_StoreActio
>>> foo_parser.
_StoreActio
>>> args = parser.
>>> parser.
Namespace(
>>> parser.
Namespace(
>>> parser.
_VersionAct
>>> foo_parser.
_StoreActio
>>> parser.
Namespace(
>>> parser.
0.1