Answers for "python argparse allowed values"

0

arg parse array argument

parser.add_argument("--list", nargs="+", default=["a", "b"])

SHELL
$ python3 example.py --list a b c
# List would look like ['a','b','c']
Posted by: Guest on September-22-2020
1

argparse accept only few options

...
parser.add_argument('--val',
                    choices=['a', 'b', 'c'],
                    help='Special testing value')

args = parser.parse_args(sys.argv[1:])
Posted by: Guest on May-08-2020

Python Answers by Framework

Browse Popular Code Answers by Language