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的第一步就是创建一个解析器对象,并告诉它将会有些什么参数.那么当你的程序运行时,该解析器就可以用于处理命令行参数. 解 ...
随机推荐
- ios ideviceintaller安装
1.安装brew 打开终端输入: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/inst ...
- RF安装
参考: http://www.cnblogs.com/zlj1992/p/6357373.html https://github.com/robotframework/RIDE/wiki/Instal ...
- xshell连不上虚拟机linux的解决办法(用的默认NAT模式)
1.找到Linux系统的ip地址 输入命令 ifconfig 2.打开本地网络连接 将VMnet1的ip地址设置为和虚拟机ip同一网段的ip 比如虚拟机Linux系统的ip为 192.168. ...
- 解决“Can't bind to local 8630 for debugger”错误--查杀多余进程
Can't bind to local 8630 for debugger 表明本地8630端口被占用 1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\& ...
- CSS 背景background实例
css背景background用于设置html标签元素的背景颜色.背景图片已经其他背景属性.本文章向码农介绍CSS 背景background使用方法和基本的使用实例.需要的码农可以参考一下. 一.Cs ...
- solr查询空值、null、不存在的字段的方法
正常情况下我们都是按有值的方式去搜索,但是有时候有一些字段为null,solr中就没有存储进去,我们怎么获取这个字段不存在为条件的搜索结果了,我们只需要在搜索字段前加上负号,如下图 摘要: Solr的 ...
- 动态html处理和及其图像识别
爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... Day 1 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpCli ...
- (15/24) 为webpack增加babel支持
Babel是什么? Babel是一个编译JavaScript的平台,它的强大之处表现在可以通过编译达到以下目的: 使用下一代的javaScript代码(ES6,ES7-.),即使这些标准目前并未被当前 ...
- mysql5.7.13 使用笔记
社区版下载地址:https://dev.mysql.com/downloads/mysql/ 安装:http://www.linuxidc.com/Linux/2016-04/130414.htm ...
- 21. oracle游标循环例子
事例1: create or replace procedure sp_addProjectQj( ret out number, flowid in number --流程Id) ascursor ...