I found the very useful syntax
parser.add_argument('-i', '--input-file', type=argparse.FileType('r'), default='-')
for specifying an input file or using stdin—both of which I want in my program. However, the input file is not always required. If I'm not using -i
or redirecting input with one of
$ someprog | my_python_prog
$ my_python_prog < inputfile
I don't want my Python program to wait for input. I want it to just move along and use default values.