In Python, using argparse, I want an input argument to take a variable number of files, like:
$ myScript --aParameter file1 file2 file3 ... fileN
How can do it?
parser.add_argument( "--aParameter", nargs=????, type=str,
                        help="Provide a list of files to analyze",
                        default=None)
                nargs stands for Number Of Arguments.
ArgumentParser() initializes the parser so that you can start to add custom arguments. To add your arguments, use parser. add_argument() . Some important parameters to note for this method are name , type , and required .
Metavar: It provides a different name for optional argument in help messages.
Use the kwarg nargs='+'.   That's pretty much all there is to it.  
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With