• argparse 模块使用


    import argparse,os

    data_func=["upload","download"]
    req_func=["getfunc","postfunc"]
    def func1():
    print("this func1")

    def func2():
    print("this is func2")

    parser=argparse.ArgumentParser()
    parser.add_argument('-j',"--jobid",required=False,type=str,help="this is jobid")
    parser.add_argument("-host",required=False,type=str,help="this is role of host part ")
    parser.add_argument("-f","--function",type=str,choices=(data_func+req_func))
    parser.add_argument("-r","--role",type=str,help="role of server")
    parser.add_argument("--nargs",nargs='+',help="type need list test ")
    parser.add_argument("-muti",action="append",help="muti append")
    parser.add_argument("-c","--config",required=False,type=str,help="config of run time ")
    args=parser.parse_args()
    jobid=args.jobid
    host=args.host
    role=args.role

    print(os.path.abspath('cases/Homo.py'))


    D:workspaceAutoFatesrccases>python argparseutils.py -f download -j 20190001 -r guest -host host1 --a aaa --a bbb --a 9999
    {'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': None, 'a': ['aaa', 'bbb', '9999']}

    D:workspaceAutoFatesrccases>python argparseutils.py -f download -j 20190001 -r guest -host host1 -muti aa -muti bb -muti 888
    {'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': None, 'muti': ['aa', 'bb', '888']}

    D:workspaceAutoFatesrccases>python argparseutils.py -f download -j 20190001 -r guest -host host1 --nargs 999 aa bbb
    {'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': ['999', 'aa', 'bbb'], 'muti': None}

    D:workspaceAutoFatesrccases>python argparseutils.py -f download -c exampels/testconfig.json
    {'jobid': None, 'host': None, 'function': 'download', 'role': None, 'nargs': None, 'muti': None, 'config': 'exampels/testconfig.json'}
    exampels/testconfig.json

    D:workspaceAutoFatesrccases>python argparseutils.py -f download -c exampels/testconfig.json
    {'jobid': None, 'host': None, 'function': 'download', 'role': None, 'nargs': None, 'muti': None, 'config': 'exampels/testconfig.json'}
    D:workspaceAutoFatesrccasescasesHomo.py

  • 相关阅读:
    学习canvas过程中的小菜鸟
    小菜鸟谈html语义化
    mui常用方法
    mui的侧滑菜单如何禁用手势侧滑
    ajax 传递数组参数
    LNMP状态管理命令
    LNMP相关软件目录及文件位置
    ubuntu常用命令
    Ubuntu设置允许root用户登录
    linux一键安装web环境(sh-1.3.0)
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/11912191.html
Copyright © 2020-2023  润新知