Search
 
SCRIPT & CODE EXAMPLE
 

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.
'''
Comment

PREVIOUS NEXT
Code Example
Python :: punctuation list python 
Python :: get requests from python 
Python :: how to draw shape square in python turtle 
Python :: python show only 1st element of nested lists 
Python :: RuntimeWarning: invalid value encountered in true_divide 
Python :: reset a turtle python 
Python :: django.core.exceptions.ImproperlyConfigured 
Python :: how to export data from mongodb python 
Python :: round python 
Python :: copy a file from one directroy to other using python 
Python :: max of matrix numpy 
Python :: making variable if it is none python 
Python :: print 2d array in python 
Python :: how to draw in pygame 
Python :: turn list of tuples into list 
Python :: boxplot label python 
Python :: python cv2.Canny() 
Python :: green fuel 
Python :: fuzzy lookup in python 
Python :: python run a system command 
Python :: how to cancel a input in python 
Python :: how to detect an even number in python 
Python :: find a file in python 
Python :: find the max value in dictionary python 
Python :: python catch sigterm 
Python :: unlimited keyword arguments python 
Python :: get all files in directory python 
Python :: how to output random letters in python 
Python :: django post request 403 forbidden 
Python :: weekday pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =