We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider the following cut-down script:
import argparse import pprint ap = argparse.ArgumentParser() ap.add_argument("p", nargs="?") ap.add_argument("q", nargs="?") ap.add_argument("--test", action="store_true") args = ap.parse_args() pprint.pprint(args.__dict__)
When invoked with two positional arguments and --test on either side of them, the behavior is as expected:
--test
$ python3 test.py --test a b {'p': 'a', 'q': 'b', 'test': True} $ python3 test.py a b --test {'p': 'a', 'q': 'b', 'test': True}
However, if you put --test in between the two positionals, argparse misinterprets the argument list:
$ python3 test.py a --test b usage: test.py [-h] [--test] [p] [q] test.py: error: unrecognized arguments: b
This argument list should produce the same Namespace object as the first two examples.
3.9, 3.11, 3.12
Linux
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report
Bug description:
Consider the following cut-down script:
When invoked with two positional arguments and
--test
on either side of them, the behavior is as expected:However, if you put
--test
in between the two positionals, argparse misinterprets the argument list:This argument list should produce the same Namespace object as the first two examples.
CPython versions tested on:
3.9, 3.11, 3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: