Search code examples
pythoncommand-lineargparsemultiple-file-upload

Problem with passing multiple arguments to argparse


I am currently trying to automate the process of creating a txt file that will contain the following line: We attempted to analyze example*.csv files. The example*.csv is user-defined. For this purpose, I am using argparse. I attempted to run the following command python3 text_gen.py --input example*.csv but it just throws me an error saying that I am passing multiple files. Also, just to be a bit more clear, I do not want to have the example files to be print as a list but rather look like an input I wrote above.

To make it a bit simpler I am just gonna give an example. In a folder, I have 5 different files example1.csv, example2.csv, example3.csv, example4.csv, example5.csv (the number of files varies each time). I would like to select all of these files and have them so my output looks like the one above: example*.csv in my text file.


Solution

  • The answer was given in the comments by @hpaulj. To solve the problem above one can either put quotations marks around the input or backslash before *