第十四章:应用构建模块-getopt:命令行选项解析-长格式选项

14.2.3 长格式选项
对于一个有两个选项的程序(–noarg和–witharg),长参数序列应为[‘noarg’,‘witharg=’]。

import getopt

opts,args = getopt.getopt(
    ['--noarg',
     '--witharg','val',
     '--witharg2=another'],
    '',
    ['noarg','witharg=','witharg2='],
    )
for opt in opts:
    print(opt)

由于这个示例程序没有任何短格式选项,所以getopt()的第二个参数是一个空串。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43193719/article/details/93377719