Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

argparse list

parser.add_argument('-l','--list', nargs='+', help='<Required> Set flag', 
                    required=True)
# Use like:
# python arg.py -l 1234 2345 3456 4567

parser.add_argument('-l','--list', action='append', help='<Required> Set flag', 
                    required=True)
# Use like:
# python arg.py -l 1234 -l 2345 -l 3456 -l 4567

'''
Notes: 
1. nargs='+' takes 1 or more arguments, nargs='*' takes zero or more.
2. Don't use type=list!!! - There is probably no situation where you would want
   to use type=list with argparse. Ever.
'''
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #argparse #list
ADD COMMENT
Topic
Name
6+1 =