On 21/04/14 22:05, rail shafigulin wrote:
Does anybody know if there is a way to specify groups of mutually exclusive options using argparse module?
Sorry, I didn't follow your example. Can you explain what you mean in English? What would be the outcome if you succeeded?
What could the user do and not do?
What I need is a way to specify groups of mutually exclusive options. In other wordsparser = argparse.ArgumentParser(prog='PROG') group1 = parser.add_argument_group() group2 = parser.add_argument_group() group1.add_argument('--foo', action='store_true') group1.add_argument('--bar1', action='store_false') group2.add_argument('--foo2', action = 'store_true') group2.add_argument('--bar2', action = 'store_false') mutually_exclusive_group = parser.add_mutually_exclusive_argument_group() mutually_exclusive_group.add_group(group1) mutually_exclusive_group.add_group(group2) parser.parse_args(['--foo1', '--bar1', '--bar2'])usage: PROG [-h] [--foo1, --bar1] | [--foo2, --bar2] PROG: error: argument --foo1 or bar1 not allowed with argument --foo2 or bar2
-- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
