import argparse parser = argparse.ArgumentParser() parser.add_argument("source_input", type=argparse.FileType('r'), help="The source input ...") parser.add_argument("source_output", type=argparse.FileType('w'), help="The source output ...") args = parser.parse_args()
使用就是︰
for line in args.source_input: ... args.source_output.write('end \n') args.source_input.close() args.source_output.close()
提示信息如下,簡單明暸︰
$ python test.py usage: test.py [-h] input output test.py: error: too few arguments $ python test.py -h usage: test.py [-h] input output positional arguments: source_input The source input ... source_output The source output ... optional arguments: -h, --help show this help message and exit
No comments:
Post a Comment