In an application I need to have an optional parameter. And if that parameter is given the value has a default/optional setting.
IE the following cases:
python main.py # value stored should be "None" (Or other indication optional parameter is not given
python main.py --ls # value stored should be the default value ("testdir")
python main.py --ls=otherdir # value stored should be 'otherdir'
However if the parser is setup like:
parser = argparse.ArgumentParser(description='Modify docker container definitions')
parser.add_argument('--ls', default='testdir', help="list")
it works quite differently:
python main.py # value is 'testdir'
python main.py --ls # error (missing argument)
python main.py --ls=otherdir # value is 'otherdir'
How can I make argparse work like this? Or is there a logical reason such a setup cannot work?