import argparse parser = argparse.ArgumentParser() parser.add_argument('-FILE', action='append', dest='collection', default=[], help='Add repeated values to a list', )
Using:
python argparse_demo.py -FILE "file1.txt" -FILE "file2.txt" -FILE "file3.txt"
And in your python code, you can access them in the collection variable, which will essentially be a list, an empty list by default; and a list containing an arbitrary number of arguments that you provide to it.
Calvin cheng
source share