如何将可选标志添加到命令行参数?
这样我就可以写作了
python myprog.py
或
python myprog.py -w
我试过了
parser.add_argument('-w')
But I just get an err或 message saying
Usage [-w W]
err或: argument -w: expected one argument
which I take it means that it wants an argument value f或 the -w option. What's the way of just accepting a flag?
I'm finding http://docs.python.或g/library/argparse.html rather opaque on this question.