Ricky Robinson
Ricky Robinson

Reputation: 22893

Python: argparse taking a list of variable size

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)

Upvotes: 10

Views: 4386

Answers (1)

wim
wim

Reputation: 362517

Use the kwarg nargs='+'. That's pretty much all there is to it.

Upvotes: 15

Related Questions