开发者

How to Loop over a optparse.OptionGroup values in python

I'm trying to use optparse to make a command line tool in python I have a group of options optparse.OptionGroup that I wan't to loop over to do whatever... but how do I do that ? I have:

usage = ("polotools [options]")
parser = optparse.OptionParser(version="polotools %s" % version, usage=usage)
parser.a开发者_如何学Cdd_option('--amrsim', dest='amrsim', action='store_true',
    help=('Set amr simulation mode, skips if not present'))    

groupAMR = optparse.OptionGroup(parser,'AMR simulation:',
                "ATENTION: use these options only with --amrsim")
groupAMR.add_option('--Utility', dest='Utility', action='store',
    help=('Set utility rate for AMR simulation, accept dictionary'))

parser.add_option_group(groupAMR)

(options, args) = parser.parse_args()

But in options all options get grouped togheter.. and I wan't to filter only the ones in groupAMR.


You probably want something like this after you set options:

for groupAMR_arg in groupAMR.option_list:
    print getattr(options, groupAMR_arg.dest)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜