python - Limit number of arguments passed in -


i using argparse take list of input files:

import argparse p = argparse.argumentparser() p.add_argument("infile", nargs='+', type=argparse.filetype('r'),  help="copy from") p.add_argument("outfile", help="copy to") args = p.parse_args() 

however, opens door user pass in prog /path/to/* outfile, source directory potentially have millions of file, shell expansion can overrun parser. questions are:

  1. is there way disable shell expansion (*) within?

  2. if not, if there way put cap on number of input files before assembled list?

(1) no, shell expansion done shell. when python run, command line expanded already. use "*" or '*' deactivate happens on shell.

(2) yes, length of sys.argv in code , exit if long.

also shells have built-in limit expansion.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -