开发者

How to Loop over a optparse.OptionGroup values in python

开发者 https://www.devze.com 2023-02-09 23:11 出处:网络
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'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

精彩评论

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