OptionParser模块学习
from optparse import OptionParser
import sys useage = []
test_parser = OptionParser(usage="%prog [options]",version="%prog 1.0",description="脚本概括:学习otionparser") test_parser.add_option("-f","--file",
# 这里的意思可以-f选项传递参数,也可以使用--file选项来传递参数
action="store",
# 说实话,这里没弄懂
dest="file_name",
# dest的意思-f选项或者--file选项后面传递的值会赋值给你file_name这个变量中,但是不能直接打印,后面会介绍如何打印
default="test_file",
# 如果-f选项后不传递任何的值,则默认值就是defalut赋值的值
help="input filaname",
# -f选项的帮助信息
type="string")
# -f选项后面的值的类型
test_parser.add_option("-d","--decv",
action="store",
dest="decv_name",
default="test_decv",
help="input decv name",
type="string") if __name__ == '__main__': (options,args) = test_parser.parse_args(sys.argv[:])
#用来接收选项的值
print(options.file_name)
print(options.decv_name)
print(args)
脚本测试:
1、测试-h选项
E:\python\重头开始\day41>python test_optionparser.py -h
Usage: test_optionparser.py [options] 脚本概括:学习otionparser Options:
--version show program's version number and exit
-h, --help show this help message and exit
-f FILE_NAME, --file=FILE_NAME
input filaname
-d DECV_NAME, --decv=DECV_NAME
input decv name E:\python\重头开始\day41>
2、测试--version选项
E:\python\重头开始\day41>python test_optionparser.py --version
test_optionparser.py 1.0 E:\python\重头开始\day41>
3、测试默认参数的选项
E:\python\重头开始\day41>python test_optionparser.py
test_file
test_decv
['test_optionparser.py']
4、测试-f和-d选项
E:\python\重头开始\day41>python test_optionparser.py -d "dddd" -f "fffff"
fffff
dddd
['test_optionparser.py'] E:\python\重头开始\day41>
5、测试--file和--decv选项
E:\python\重头开始\day41>python test_optionparser.py --file "ccccc" -d "aaaaa"
ccccc
aaaaa
['test_optionparser.py']
OptionParser模块学习的更多相关文章
- Python中optionParser模块的使用方法[转]
本文以实例形式较为详尽的讲述了Python中optionParser模块的使用方法,对于深入学习Python有很好的借鉴价值.分享给大家供大家参考之用.具体分析如下: 一般来说,Python中有两个内 ...
- Day5 - Python基础5 常用模块学习
Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...
- # nodejs模块学习: express 解析
# nodejs模块学习: express 解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的基础不稳固,需要开发者创造大量的轮子 ...
- python中的optionParser模块
Python 有两个内建的模块用于处理命令行参数:一个是 getopt,<Deep in python>一书中也有提到,只能简单处理 命令行参数:另一个是 optparse,它功能强大,而 ...
- 【转】Python模块学习 - fnmatch & glob
[转]Python模块学习 - fnmatch & glob 介绍 fnmatch 和 glob 模块都是用来做字符串匹配文件名的标准库. fnmatch模块 大部分情况下使用字符串匹配查找特 ...
- pythone函数基础(7)第三方模块学习
一,time模块学习 import time # print(int(time.time()))#时间戳# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式 ...
- python中confIgparser模块学习
python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...
- Python logging 模块学习
logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...
- python - argparse 模块学习
python - argparse 模块学习 设置一个解析器 使用argparse的第一步就是创建一个解析器对象,并告诉它将会有些什么参数.那么当你的程序运行时,该解析器就可以用于处理命令行参数. 解 ...
随机推荐
- mdm9x07 ATC AT+QCFG usbnet
1 中文AT命令详解 1.1. AT+QCFG 扩展配置 AT+ QCFG 扩展配置 测试命令 AT+QCFG=? 响应 …… +QCFG: "usbnet" ...
- 用 tornado 做网站 (7)
转自:http://wiki.jikexueyuan.com/project/start-learning-python/309.html 用 tornado 做网站 (7) 到上一节结束,其实读者已 ...
- BPM与ESB
BPM:业务流程管理 --监控处理流程的轨迹以及处理过程 开源:JBPM 场景: 1.单一系统的协同工作比如审批流程,请假流程 2.多个系统的集成,复用各个子系统,构建新的处理流程(流程的优化与流程 ...
- python第一个爬虫的例子抓取数据到mysql,实测有数据
python3.5 先安装库或者扩展 1 requests第三方扩展库 pip3 install requests 2 pymysql pip3 install pymysql 3 lxml pip3 ...
- CUDA C Programming Guide 在线教程学习笔记 Part 8
▶ 线程束表决函数(Warp Vote Functions) ● 用于同一线程束内各线程通信和计算规约指标. // device_functions.h,cc < 9.0 __DEVICE_FU ...
- 15. Studio上字符串转整形、整形转字符串例子
var v1=ABS_SQLVALUE("select 1 from dual");var v2=ABS_SQLVALUE("select 2 from dual&quo ...
- leetcode504
public class Solution { public string ConvertToBase7(int num) { ? "" : "-"; var ...
- thymeleaf的使用
1.导包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- AJAX服务器返回数据 连接数据库查询数据
getcustomer.asp" 中的源代码负责对数据库进行查询,然后用 HTML 表格返回结果: <% response.expires=-1 sql="SELECT * ...
- C++ 实现的netstat -an 的功能<转>-目的为获取rtmp推流地址如果是域名的话查看1935的ip
目的可能是为了获取rtmp真正的推流ip 如果rtmp推流地址是域名,往CDN推流的话,需要nslookup 的那种DNS解析,然后获取的几个ip 可以使用netstat -n 等命令查看 1935 ...