I am using python argparse to read an optional parameter that defines an "exemplar file" that users sometimes provide via the command line. I want the default value of the variable to be empty, that is no file found.
parser.add_argument("--exemplar_file", help = "file to inspire book", default = '')
Will this do it?
Just don't set a default:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--exemplar_file', help='file to inspire book')
args = parser.parse_args()
print(args.exemplar_file)
# Output:
# None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With