When specifying the same argument multiple times, the default argparse behaviour is that the last specified value "wins", overwriting the previous value. I want argparse to show an error when the same argument is specified multiple times instead of silently overwriting the first specified value.
How can that be done?
My current code:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'-t', '--test', # either of this switches
type=str, # parameter is string
dest='test', # store in 'test'.
required=True # required
)
Calling the script:
myscript.py -t hello -t world
leads to no errors, test
has the value world. I want argparse to show an error in this case, as the default behaviour is error prone from my point of view.