i am working on a project where i have a raw data that i need to extract from each txt file (around 300 000) only once and move to another batch of 300 000 files. And there for i need to open each txt file one after the other in a effetion way posible to minimize the time of this process. I'm using open() but it can take up to 10-15 min for avg 160 000 txt files no more than 600 bytes each.
Thank you for your time :)
for filename in os.listdir("folder1"):
with open(os.path.join("folder1", filename), 'r') as f:
text = f.read()
text = re.findall(r'\w+', text)
index = 0
while index < len(text):
if text[index] == "P1":
function1(text)
elif text[index] == "T1":
function2(text)
index += 1