Answer the question
In order to leave comments, you need to log in
ArgParse: mutually exclusive arguments in place of positional?
You need to pass data to the script either from a file or from the command line.
I am using the construct:
parser_write = subparsers.add_parser('write', help='Write вфеф')
parser_write.add_argument('address', type=int)
parser_write_data = parser_write.add_mutually_exclusive_group(required=True)
parser_write_data.add_argument('-f', help='Data as binary file', type=argparse.FileType(), metavar=('FILE'))
parser_write_data.add_argument('data', help='Data as hex string', nargs='?')
usage: script.py write [-h] [-f FILE] address [data]
positional arguments:
address
data Data as hex string
optional arguments:
-h, --help show this help message and exit
-f FILE Data as binary file
usage: script.py write [-h] address {data|-f FILE}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question