python argsparse

2022/8/24 1:22:46

本文主要是介绍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)


这篇关于python argsparse的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程