If I call the script below with these options:
--user u1 --password p1 --foo f1 --user u2 --user u3 --password p3
Then it will print:>
Define a custom user type which holds both username and password.
def user(s): try: username, password = s.split() except: raise argparse.ArgumentTypeError('user must be (username, password)') group.add_argument('--user', type=user, action='append')