How can I open many files at same time in the python programming language to run my program?
I have about 15 files, just now I have worked with one of them like below:
f=open("Exemplo_1.txt","rU")
Python provides the ability to open as well as work with multiple files at the same time. Different files can be opened in different modes, to simulate simultaneous writing or reading from these files.
Hence, there can be at most 95141 possible file descriptors opened at once. To change this use: where 104854 is max number which you want. I agree with everyone else here.
You could use a combination of glob
and fileinput
import fileinput
from glob import glob
fnames = glob('Exemplo_*.txt')
for line in fileinput.input(fnames):
pass # do whatever
f1=open("Exemplo_1.txt","rU");
f2=open("Exemplo_2.txt","rU");
...
f15=open("Exemplo_15.txt","rU");
You're basically creating File objects to get access to the files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With