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:
is there way disable shell expansion (*) within?
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
Post a Comment