Python argparse用法
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用法的更多相关文章
- python argparse用法总结
转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...
- 【转】python argparse用法总结
转自:https://www.jianshu.com/p/fef2d215b91d 1. argparse介绍 是python的一个命令行解析包,非常编写可读性非常好的程序 2. 基本用法 prog. ...
- 转载:python argparse用法总结
https://www.jianshu.com/p/fef2d215b91d 1. argparse介绍 是python的一个命令行解析包,非常编写可读性非常好的程序 2. 基本用法 prog.py是 ...
- Python argparse 用法总结
使用argparse的四个基本步骤 创建 ArgumentParser() 对象 调用 add_argument() 方法添加参数 使用 parse_args() 解析添加的参数 # example ...
- Python argparse 处理命令行小结
Python argparse 处理命令行小结 1. 关于argparse是python的一个命令行解析包,主要用于处理命令行参数 2. 基本用法test.py是测试文件,其内容如下: import ...
- python argparse库
argparse用法总结 https://blog.csdn.net/qq_24551305/article/details/90155858 args = parse.parse_args()par ...
- Python高级用法总结
Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...
- Python argparse 模块
Python argparse 模块 test.py: import argparse argparser = argparse.ArgumentParser(add_help=False) argp ...
- python argparse sys.argv
python argparse sys.argv class WeiLearningArgumentParser(argparse.ArgumentParser): def __init__(self ...
随机推荐
- Unity资源内存管理--webstream控制
一 使用前提 1,需要使用资源热更新 2,使用Assetbundle资源热更(AssetBundle是产生webstream的元凶) 二 为什么要用AssetBundle AssetBundle本质上 ...
- 如何用ESP8266/8285做一个WIFI广告机(虚拟WiFi)
准备工作 准备一个深圳四博智联科技有限公司的ESP-F 模组.或者四博智联科技的NODEMCU 当我们拿到ESP-F模块后,可以按照以下接线进行测试: 即 VCC.EN 接 3.3v.GPIO15 G ...
- 手动增加swap空间
在日常工作中,swap没有必要搞那么大的空间,因为现在好多服务器都使用了ssd硬盘,这些硬盘还是比较贵的.如果服务器内存是128G,swap空间还设置成内存的两倍的话,那岂不是很明显是很 ...
- 页面制作学习笔记:D1.概述
一.Web发展历史 Web1.0 :早期HTML页面:例:网易的门户网站163.com. Web2.0:AJAX技术规模应用:例:网易邮箱126.com. Web3.0:HTML5技术规模应用:例:网 ...
- python中的lambda表达式
lambda是python中匿名函数的写法 我们可以在不定义函数名的情况下一边定义并调用这个函数 例子: 普通方法定义函数:def plus(a,b): return a+b lambda方法 ...
- mac下修改mysql默认字符集为utf8
1.首先检查默认安装的字符集 mysql> show variables like '%char%'; +--------------------------+----------------- ...
- day 29 元类
---恢复内容开始--- 一.元类的介绍 元类:在python里,一切皆对象.所有自定义的类本身也是元类的对象,即所有自定义的类本质上也是由元类实例化出来的. class关键字创建自定义类的底层的工作 ...
- Ubuntu的显示问题不全解决
首先我们安装的是Ubuntu 16.04版本.最开始一直不能解分辨率问题,导致信息显示不全 利用xrandr -s 1369x768(中间x是乘号不是英文字母) 命令来设置分辨率, 需注意的是: 1. ...
- Strongly connected components
拓扑排列可以指明除了循环以外的所有指向,当反过来还有路可以走的话,说明有刚刚没算的循环路线,所以反过来能形成的所有树都是循环
- Java课程----自我介绍
我是一名信息院的学生,今年今日是大二下学期,马上就要大三了,自己对于专业的认知还是太浅.主要是因为之前的大学生活特别懒散,并不积极向上.但是我想说的是,我们大学生,一定不要碌碌无为,要有所作为.我 ...