Using argparse, is it possible to stop parsing arguments at the first unknown argument?
I’ve found 2 almost solutions;
parse_known_args, but this allows for known parameters to be detected after the first unknown argument.nargs=argparse.REMAINDER, but this won’t stop parsing until the first non-option argument. Any options preceding this that aren’t recognised generate an error.
Have I overlooked something? Should I be using argparse at all?
I haven’t used
argparsemyself (need to keep my code 2.6-compatible), but looking through the docs, I don’t think you’ve missed anything.So I have to wonder why you want
argparseto stop parsing arguments, and why the--pseudo-argument won’t do the job. From the docs: