Andrew
Andrew

Reputation: 6900

How do I require the full argument names in argparse?

By default argparse will accept unambiguous prefixes as named arguments. E.g. if I have an argument --arg1, argparse will accept --ar (if I have another argument with --ar prefix it would complain). I want to force argparse to require the full argument name and not just prefixes - that is, only --arg1 would work in my example - --ar would fail.

Upvotes: 1

Views: 321

Answers (1)

thyago stall
thyago stall

Reputation: 1704

If you are using python 3.5 onwards, you can use:

parser = argparse.ArgumentParser(allow_abbrev=False)

Before that, there is no documented way of doing it. Unless you make your own hacks for it.

Upvotes: 3

Related Questions