#!/usr/bin/env python """ how the number of arguments can be specified """ import argparse def main(): parser = argparse.ArgumentParser( formatter_class = argparse.RawDescriptionHelpFormatter, description="This is an example" ) parser.add_argument('-f', dest="force", action="store_true", help='force delete, no confirmation') # # positional arguments # parser.add_argument( 'names', nargs='*', help='some names') # # exactly 2 arguments # parser.add_argument('--par1', nargs=2, default = "defValue") # # One argument will be consumed from the command line if possible, # produced as a single item, not a list # parser.add_argument('--par2', nargs='?', default = "defValue") # # all arguments are collected into a list # parser.add_argument('--par3', nargs='*', default = "defValue") # # all arguments are collected into a list, minimum 1 # parser.add_argument('--par4', nargs='+', default = "defValue") args = parser.parse_args() print( "%s" % repr( args)) return if __name__ == "__main__": main()