Reputation: 15
I'm making a program which requires me to create csv files with names that are generated by the script. Therefore I cannot open the csv file using
open("file.csv")
but I have to use a variable to get the name:
open("%s.csv" % x)
This, however gives me this error:
FileNotFoundError: [Errno 2] No such file or directory: '.csv'
The files are automatically saved in the same folder as my script, and I have tested to make sure the variable works and gives the name of the file.
Upvotes: 0
Views: 65
Reputation: 46
Assuming, you have lots of file-name and you have stored them in List(allfileslist).
for name in allfileslist:
name=name+".csv"
f = open(name,"w+")
f.close()
Upvotes: 2