import argparse
import sys parser = argparse.ArgumentParser(description='this is for test.') parser.add_argument("-i", "--app_id", help="Custom app id")
parser.add_argument("-d", "--config_dir", help="Custom config directory")
parser.add_argument("-f", "--config_file", help="Custom config file name "
"(in config directory)")
args = parser.parse_args(sys.argv[1:]) # Set default parameters
app_id = 0000
config_dir = 'test_dir'
config_file = 'test_file' if args.app_id:
app_id = args.app_id if args.config_dir:
config_dir = args.config_dir if args.config_file:
config_file = args.config_file print('APP_ID: {}, CONFIG_DIR: {}, CONFIG_FILE: {}.'.format(app_id, config_dir, config_file))

  

python.exe .\test.py -h
usage: test.py [-h] [-i APP_ID] [-d CONFIG_DIR] [-f CONFIG_FILE]

this is for test.

optional arguments:
-h, --help show this help message and exit
-i APP_ID, --app_id APP_ID
Custom app id
-d CONFIG_DIR, --config_dir CONFIG_DIR
Custom config directory
-f CONFIG_FILE, --config_file CONFIG_FILE
Custom config file name (in config directory)

python.exe .\test.py -i 123 -d dir -f file
APP_ID: 123, CONFIG_DIR: dir, CONFIG_FILE: file.

Python argparse用法的更多相关文章

  1. python argparse用法总结

    转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...

  2. 【转】python argparse用法总结

    转自:https://www.jianshu.com/p/fef2d215b91d 1. argparse介绍 是python的一个命令行解析包,非常编写可读性非常好的程序 2. 基本用法 prog. ...

  3. 转载:python argparse用法总结

    https://www.jianshu.com/p/fef2d215b91d 1. argparse介绍 是python的一个命令行解析包,非常编写可读性非常好的程序 2. 基本用法 prog.py是 ...

  4. Python argparse 用法总结

    使用argparse的四个基本步骤 创建 ArgumentParser() 对象 调用 add_argument() 方法添加参数 使用 parse_args() 解析添加的参数 # example ...

  5. Python argparse 处理命令行小结

    Python argparse 处理命令行小结 1. 关于argparse是python的一个命令行解析包,主要用于处理命令行参数 2. 基本用法test.py是测试文件,其内容如下: import ...

  6. python argparse库

    argparse用法总结 https://blog.csdn.net/qq_24551305/article/details/90155858 args = parse.parse_args()par ...

  7. Python高级用法总结

    Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...

  8. Python argparse 模块

    Python argparse 模块 test.py: import argparse argparser = argparse.ArgumentParser(add_help=False) argp ...

  9. python argparse sys.argv

    python argparse sys.argv class WeiLearningArgumentParser(argparse.ArgumentParser): def __init__(self ...

随机推荐

  1. Get teststep of specific type

    SoapUI Groovy : Check if test step is of specific type, such as : Wsdl, Rest, Jdbc, HTTP, Groovy etc ...

  2. 关于系统弹出错误:429 , ActiveX 部件不能创建对象 的解决方法

    例如:win7 win10的系统,有时候运行某些软件会出现:429 , ActiveX 部件不能创建对象 的情况. 提示: "运行时错误'429': ActiveX 部件不能创建对象&quo ...

  3. 1023. Have Fun with Numbers (20)

    生词以及在文中意思 duplication 重复 permutation 排列 property 属性 import java.util.Scanner; public class Main { pu ...

  4. poj3162(树形dp+优先队列)

    Walking Race Time Limit: 10000MS   Memory Limit: 131072K Total Submissions: 5409   Accepted: 1371 Ca ...

  5. verilog reg 初值问题

    虽然没有写初值 但是硬件电路肯定有逻辑电平的如果是用fpga实现的 缺省值为全0 也可以在信号声明时指定初始值如果是asic实现 初始值是随机的(但也是某个电平) 声明时指定初值会被忽略 rtl仿真时 ...

  6. Linux:Gentoo系统的安装笔记(二)

    这期笔记继续安装Gentoo,上期我们已经到了可以进入新环境了,这意味着就是将原来的安装CD或其它介质改为硬盘上安装系统了,话不多说,马上开始! 恢复安装 由于我已经中断了安装,对于已经可以进入新环境 ...

  7. python模块之os_sys_动态导入_包

    os模块: #!/usr/bin/env python # coding:utf-8 import os print(os.getcwd()) #获取当前工作目录,即当前python脚本工作的目录路径 ...

  8. MVC部署阿里云躺过的坑

    1.端口问题 服务器上的80端口默认是打开的.但要能用必须在阿里云的安全组添加对应的配置. 2.安装IIS 在Windows Service 2012 安装IIS,安装时勾一个总复选框,但有些该分支下 ...

  9. WebStorm 破解方法

    WebStorm 破解方法 第一步 打开 IntelliJ IDEA 注册码 网址,点击下载最新的 破解补丁 第二步 将下载下来的破解补丁,复制到WebStorm 安装目录的bin目录下 第三步 修改 ...

  10. [LeetCode&Python] Problem 671. Second Minimum Node In a Binary Tree

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...