I have a program that uses the default username and password. I use argparse to allow the user to specify command line options, and I would like to enable the user to provide the program with a different username and password to use. Therefore, I have the following:
parser.add_argument( '-n', '--name', help='the login name that you wish the program to use' ) parser.add_argument( '-p', '--password', help='the password to log in with.' )
But it makes no sense to specify only a name or only a password, but it would be pointless to specify any. I noticed that argparse has the ability to indicate that the two arguments are mutually exclusive. But I have two arguments that should come together. How do I get this behavior? (I found the “argument groups” mentioned in the docs, but they don't seem to solve my problem http://docs.python.org/2/library/argparse.html#argument-groups )
python command-line-arguments argparse
jononomo Jan 16 '13 at 2:10 2013-01-16 02:10
source share