python3 getopt用法
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用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angular中父组件给子组件传值-@i
- 下一篇: Git 的介绍使用以及简单操作流程