python 使用optparse的代码段示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用optparse的代码段示例相关的知识,希望对你有一定的参考价值。

# just a short example of using optparse
import getpass
import optparse

# def parseCmdArgs():
cmdOpts = optparse.OptionParser(usage = '%prog [options]')
cmdOpts.add_option('-i', dest = 'ipaddr', help = 'IP address of CIMC')
cmdOpts.add_option('-u', dest = 'user', help = 'Username')
cmdOpts.add_option('-p', dest = 'passwd', help = 'Password (Optional. If not provided you will be prompted.)')
cmdOpts.add_option('-l', action = 'store_true', dest = 'list', help = 'Just query running firmware.')
cmdOpts.add_option('-v', action = 'store_true', dest = 'verbose', help = 'Verbose output')
cmdOpts.add_option('-n', action = 'store_true', dest = 'dry', help = 'Dry run')
(opts, args) = cmdOpts.parse_args()

def getpassword(prompt = "CIMC Password: "):
    return getpass.unix_getpass(prompt)%       

以上是关于python 使用optparse的代码段示例的主要内容,如果未能解决你的问题,请参考以下文章

python 显示了如何使用optparse模块的简单示例

python OptParse示例

python 模块 optparse

python optparse模块学习

python中optparse模块用法

Python中optparse模块使用浅析