python channel_builder.py -s /Users/graypn/ -d /Users/graypn/Documents -m 7 --out=report/xx.html参数也分长格式和短格式短格式:-s
长格式:--sourceopts, args = getopt.getopt(sys.argv[1:], "hs:d:m:v:p:c:",
["help", "src=", "dst=", "major=", "version=", "platform=", "channels="])这个 opts 是一个字典类型,getopt.getopt(x,y,z) x函数第一个传入参sys.argv[1:],y第二个传段short短数名"hs:d:m:v:p:c:",z第三个是long长参数名["help", "src=", "dst=", "major=", "version=", "platform=", "channels="]short 用法就是  python   test.py  -h 111
long用法可以2种  --out=res/tt.html
或者直接  --out  res/tt.html
关于第二个参数初学者会很困惑这啥意思:
其实是这样的单独一个字母表示该参数不带值,一个字母加个:比如p:表示该参数后面带值,"hf:-v"也可以写成'-h-f:-v',到底什么意思呢:

  

C:\Users\Administrator\PycharmProjects\checkTest\src>python xx.py -h
this is --help

C:\Users\Administrator\PycharmProjects\checkTest\src>python xx.py -f
Traceback (most recent call last):
File "xx.py", line 22, in <module>
opts, args = getopt.getopt(sys.argv[1:], '-hf:-v', ['help', 'filename=', 'version'])
File "C:\Python37\lib\getopt.py", line 95, in getopt
opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
File "C:\Python37\lib\getopt.py", line 199, in do_shorts
opt)

getopt.GetoptError: option -f requires argument

C:\Users\Administrator\PycharmProjects\checkTest\src>python xx.py -h 
this is --help

C:\Users\Administrator\PycharmProjects\checkTest\src>python xx.py -f=aaaa.txt
[*] Filename is =aaaa.txt

意思就是你短参数不需要给我指定值,给我我也没发接受处理比如1000短参数给的值1000也没用,长参数是你必须给我值我才可以进行传参

转载于:https://www.cnblogs.com/SunshineKimi/p/10903421.html

python3 getopt用法相关推荐

  1. Python3基本用法 2020.2.20

    Python3基本用法 2020.2.20 Python3简介 Python是一个高层次的结合了解释性.编译性.互动型和面向对象的脚本语言. Python的设计具有很强的可读 %8.5f格式说明符表示 ...

  2. Shell命令 getopts/getopt用法详解 命令行参数

    Shell命令行参数解析getopts/getopt用法详解 在Linux bash中,可以用以下三中方式解析命令行参数: 直接处理:使用$1.$2.$3- 进行解析 getopts:短选项的情况,例 ...

  3. 【python】命令行解析工具getopt用法

    处理命令行参数的模块 用法: opts, args = getopt.getopt( sys.args[1:],  shortStr,  longList) 输入: shortStr 形式如下: &q ...

  4. python getopterror_python3 getopt用法

    python channel_builder.py -s /Users/graypn/ -d /Users/graypn/Documents -m 7 --out=report/xx.html 参数也 ...

  5. C处理命令行参数 getopt 用法

    2019独角兽企业重金招聘Python工程师标准>>> http://www.youtube.com/watch?v=SjyR74lbZOc 这个视频比较专业,可爱 http://w ...

  6. python3 not 用法

    在python中not是逻辑判断词,用于布尔型True和False,not True为False,not False为True,以下是几个常用的not的用法: (1) not与逻辑判断句if连用,代表 ...

  7. python3 isinstance用法_对python中assert、isinstance的用法详解

    1. assert 函数说明: Assert statements are a convenient way to insert debugging assertions into a program ...

  8. python3.7用法_Python 3.7中dataclass装饰器用法详解

    Python 3.7的dataclass装饰器用法 Python 3.7新功能之dataclass装饰器详解 前言 Python 3.7 将于今年夏天发布,Python 3.7 中将会有许多新东西: ...

  9. getopt()用法详解

    getopt被用来解析命令行选项参数.就不用自己写东东处理argv了. #include <unistd.h>extern char *optarg; //选项的参数指针extern in ...

最新文章

  1. SQL中返回一个字符串在另一个中存在的次数
  2. python跳出双层for循环的解决方法
  3. 成功解决object_detection/protos/*.proto: No such file or directory
  4. 绝对好文:嵌入式系统的软件架构设计!
  5. 网络交换机的分类介绍
  6. 摄影平铺海报psd模板|简单搭建层次场景海报
  7. 物理频率、模拟角频率、数字角频率和归一化数字角频率个人理解
  8. 【Lolttery】项目开发日志 (七)socket io 结合 react js实现简单聊天室
  9. 在托管 Windows 服务中承载 WCF 服务
  10. php使用ffmpeg转录网络直播流,使用FFmpeg转录网络直播流
  11. 资深解毒:盖码饭和盖浇饭的区别是什么?
  12. 你的功夫真的夠了嗎?
  13. 小程序云开发 免费版 云函数数量超过限制 怎么办
  14. file api java_File的API和常用方法详解_动力节点Java学院整理
  15. python程序设计基础教程骆焦煌答案_清华大学出版社-图书详情-《C语言程序设计教程》...
  16. ps的两种填充效果快捷键
  17. CCPC-2017 杭州站B丨HDU - 6265丨数论丨积性函数 丨欧拉函数丨狄利克雷卷积丨思维变换
  18. Python爬取猫眼「碟中谍」全部评论
  19. 众筹网站项目第四天之异步请求的分页查询和模糊条件查询(2)
  20. 《奇特的一生》读书笔记

热门文章

  1. 电脑桌面便签_电脑桌面定时提醒记事本便签软件
  2. mysql 加1_[MySQL场景系列之三] 加一操作
  3. Python连接DM8数据库
  4. 每天一道LeetCode-----从有序数组中删除重复元素
  5. 1015 德才论 (25 分)(c语言)
  6. 记录spark-yarn模式下提交自己写的java程序
  7. mac 10.10.5 mysql_Macbook os x 10.10.5 下装mysql 一些记录
  8. 删除 Mac AppStore 正在下载的应用
  9. Pixhawk原生固件PX4之串口添加读取传感器实现
  10. ASCII表完整版(包含16进制对应表)