10

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)
0

1 Answer 1

15

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

Sign up to request clarification or add additional context in comments.

2 Comments

Or, nargs='*' if you want to support the ability to have an empty list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.