fromoptparseimportOptionParserparser=OptionParser()parser.add_option('-p','--pdbk',action='store_true',dest='pdcl',default=False,help='write pdbk data to oracle db')parser.add_option('-z','--zdbk',action='store_true',dest='zdcl',default=False,help='write zdbk data to oracle db')(options,args)=parser.parse_args()ifoptions.pdcl==True:print'pdcl is true.'ifoptions.zdcl==True:print'zdcl is True.'
fromoptparseimportOptionParserparser=OptionParser()parser.add_option('-f','--file',dest='filename',metavar='FILE',help='write report to FILE')parser.add_option('-q','--quit',action='store_false',dest='verbose',default=True,help='Don\'t print status message to stdout.')(options,args)=parser.parse_args()
group=OptionGroup(parser,'Dangerous Options','Caution: use these options at your own risk. It is believed that some of them bite.')group.add_option('-g',action='store_true',help='Group option.')parser.add_option_group(group)
version 创建OptionParser对象时指定该参数,会解释成 --version 命令行参数