2 ms·
"Better" only if you want the default error message. As the second rated answer for the question comments: "If you like to have more control about error message
by eesmith 8y ago
"Better" only if you want the default error message. As the second rated answer for the question comments: "If you like to have more control about error message and the like, you can of course check the results later"
For example, this code:
import argparse
parser = argparse.ArgumentParser()
g = parser.add_mutually_exclusive_group()
g.add_argument("--queries",help="queries help")
g.add_argument("--hex-query",help="hex-query help")
g.add_argument("--query",help="query help")
args = parser.parse_args()
print(args)
When passed the command-line arguments "--hex-query AB --query CD --queries ASDF" it gives:
error: argument --query: not allowed with argument --hex-query
My code gives:
error: Can only specify at most one of --query, --hex-query, or --queries