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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -