I want to store TRUE/FALSE when the parameters are passed in the command line. But if nothing is present after the parameter name or the parameter isn't specified, it should store TRUE. The code below does it for the most part, except that it stores NONE when simply --stoplogging is specified (as in 2nd desired output)
import argparse
parser=argparse.ArgumentParser()
parser.add_argument('--stoplogging', action='store', default="True", nargs='?')
args=parser.parse_args()
print(args)
Actual Output:
>>>python test.py
>>>Namespace(stoplogging='True')
>>>python test.py --stoplogging
>>>Namespace(stoplogging='None')
>>>python test.py --stoplogging=True
>>>Namespace(stoplogging='True')
>>>python test.py --stoplogging=False
>>>Namespace(stoplogging='False')
Desired output:
>>>python test.py
>>>Namespace(stoplogging='True')
>>>python test.py --stoplogging
>>>Namespace(stoplogging='True')
>>>python test.py --stoplogging=True
>>>Namespace(stoplogging='True')
>>>python test.py --stoplogging=False
>>>Namespace(stoplogging='False')