Python模块optparse
来源:互联网 发布:仓库平面图绘图软件 编辑:程序博客网 时间:2024/05/16 17:53
optparse模块是处理命令行参数的,它功能强大,而且易于使用,可以方便地生成标准的、符合Unix/Posix 规范的命令行说明
一个简单的optparse实例
from optparse import OptionParser[...]parser = OptionParser()parser.add_option("-f", "--file", dest="filename", help="write report to FILE", metavar="FILE")parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout")(options, args) = parser.parse_args()
短选项和长选项,-f和--file功能一样
(options, args) = parser.parse_args()
options得到的是dest值作为字典的键,参数值作为键值的字典
dest=“filename” 表示filename为options字典中的键,-f outfile则表示outfile是options字典中filename对应的值
action="store_false"表示存储的是布尔值True或False
默认action的值为store表示存储的是选项对应的值
default=True 默认存储的值为store_false或store_true中的false或true
help= "this is a file option" 选项说明信息
<yourscript> -h显示选项帮助信息
0 0
- Python optparse模块
- python模块学习---optparse
- 【python】optparse 模块
- python optparse模块
- Python模块optparse
- Python optparse模块
- Python中的optparse模块
- Python--模块之optparse
- python optparse命令解析模块
- python中optparse模块用法
- Python 中 optparse模块简介
- Python模块整理:选项模块Optparse
- 深入理解python 命令行解析模块optparse(optparse源代码解读)
- Python模块学习——optparse
- python中命令行处理--optparse模块
- Python模块学习——optparse
- Python模块学习——optparse
- Python模块学习——optparse
- HMM学习笔记_3(从一个实例中学习Viterbi算法)
- IPhone之NSXMLParser的使用
- UART , 通信模型, 协议
- 输入板火爆App Store 搜狗无线战略渐清晰
- 读懂Spring核心系列4(XML文件配置)
- Python模块optparse
- Android PhoneStateListener
- linux 与 windows 编译 生成文件对比
- CodeForces-266A-Stones on the Table
- 数据结构和算法——二叉排序(查找)树及实现
- Struts2.3.16.1Hibernate4.3.4Spring4.0.2 整合
- NoSQL的三大基石(CAP、BASE和最终一致性)
- CALayer与UIView
- 解压缩版MySQL环境配置及入门