paul j3 added the comment: Another way to add an existing Action to a group is to modify the 'add_argument' method for the Group subclass. For example we could add this to the _MutuallyExclusiveGroup class:
def add_argument(self, *args, **kwargs): # allow adding a prexisting Action if len(args) and isinstance(args[0], Action): action = args[0] return self._group_actions.append(action) else: return super(_MutuallyExclusiveGroup, self).add_argument(*args, **kwargs) With this the 1st example might be written as: group1 = parser.add_mutually_exclusive_group() a_action = parser.add_argument('-a') c_action = parser.add_argument('-c') group2 = parser.add_mutually_exclusive_group() group2.add_argument(a_action) d_action = parser.add_argument('-d') This might be more intuitive to users. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10984> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com