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. python 时间字符串
  2. 神经网络中归一化的重要作用
  3. win 7 新建文件夹 new folder Item Not Found 解决办法
  4. JS 面向对象与原型
  5. mysql存储过程和游标遍历
  6. python表情符号编码大全_Emoji的编码以及常见问题处理
  7. 解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails
  8. 〖谷腾读书会GTC〗Digital economy
  9. 西餐美食店响应式网站模板
  10. [詹兴致矩阵论习题参考解答]习题1.13
  11. python2.7安装sqlite3模块
  12. webpack的简介---webpack工作笔记001
  13. Unity开发手游的实用插件
  14. laravel较优雅的分表关联查询(性能较好,SQL的数量=表的数量,涵盖了较多laravel手册推荐的方法)...
  15. 极品飞车14! u9gt2完美全屏运行
  16. 分布式计算 lab2 Java RMI
  17. Python实现爬取腾讯招聘网岗位信息
  18. 3.知识图谱业务落地技术推荐之国内知识图谱平台汇总(竞品)[阿里、腾讯、华为等】
  19. 人类月球日 | 专访邹海洋:中国的航天梦,是信任与不辜负的故事
  20. Vue搜索框显示最近(历史)搜索记录

热门文章

  1. 关于JetBrains CLion 激活 (CLion License Activation)的解决办法,带hosts详细修改
  2. mybatis里的日志动态代理
  3. Shell(7)——case
  4. Apache(2)——进程与模块
  5. PHP处理Checkbox复选框表单提交
  6. XShell配置Socket5代理
  7. pixhawk博客导读
  8. HDU 2570 迷瘴
  9. 翻转字符串里面的单词(*****)
  10. 【Linux】目录组织结构、文件类型和文件权限