1

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.add_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.

1 Answer 1

1

You probably want something like this after you set options:

for groupAMR_arg in groupAMR.option_list:
    print getattr(options, groupAMR_arg.dest)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.