I am trying to sort out how to pass the boolean value False from the command line to the argparser. My origninal code looked like:
import argparse
parser = argparse.ArgumentParser(allow_abbrev=True)
parser.add_argument('-data', default=True, type=bool, help='uses the history file')
args = parser.parse_args(sys.argv[1:])
From the command line, I typed: python myscript.py -data False
Also variations with single & double quotes around False. When I examine the contents of the args namespace, args.data is always True.
So I changed the argument definition from bool to str, with a string "True" default as shown below:
parser.add_argument('-data', default="True", type=str, help='uses the history file')
I then added some massaging of the args to get the boolean value I really wanted:
if re.search("f", args.data, re.I):
args.data = False
else:
args.data = True
This workaround does work. Is there a better way to do this?