python argsparse

python 运行时参数设置


import argparse


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Process some integers.')
    parser.add_argument("-c","--config",nargs="?",help='python main.py -c config.json') #-c 后面只有一个参数
    parser.add_argument("-f","--file",nargs="*",help='python main.py -f file1 file2 file3...')#-f 后面可以有很多个参数
    parser.add_argument("-o","--out_dir",nargs="?",help='python main.py -o /data/') #-o后面可以有一个参数
    args = parser.parse_args()
    print(args.config)
    print(args.file)
    print(args.out_dir)
posted @ 2022-08-23 18:16  simp00  阅读(93)  评论(0编辑  收藏  举报