So I’m working on a program where I store data into multiple .txt files. The naming convention I want to use is file”xx” where the Xs are numbers, so file00, file01, … all the way up to file20, and I want the variables assigned to them to be fxx (f00, f01, …).
How would I access these files in Python using a for loop (or anther method), so I don’t have to type out open("fileXX") 21 times?
An example of writing
tto all files:I use the
execstatement but there’s probably a better way. I hope you get the idea though.NOTE: This method will give you the variable names
fXXto work with later if needed. The last two lines are just examples. Not really needed if all you need is to assignfileXX.txttofXX.EDIT: Removed the other last two lines because it seemed that people just weren’t too happy with me putting them there. Explanations for downvotes are always nice.