I’m building a script which uses arguments to configure the behavior and shall read an undefined number of files. Using the following code allows me to read one single file. Is there any way to accomplish that without having to set another argument, telling how many files the script should read?
parser = argparse.ArgumentParser()
parser.add_argument("FILE", help="File to store as Gist")
parser.add_argument("-p", "--private", action="store_true", help="Make Gist private")
Yes, change your
"FILE"line to:This will gather all the positional arguments in a list instead. It will also generate an error if there’s not at least one to operate on.
Check out the nargs documentation