Sep-17-2021, 05:48 PM
So the file contains a line with "(3i9,6e21.13e3)", we see on the image you show us. But are there perhaps (invisible) spaces after this text? In that case you had better test with:
Like this (untested):
if line.startswith("(3i9,6e21.13e3)"):Another thing you are not asking for is this: you emphasize the file is huge. But in your code you use "old_database.readlines()". You must be aware that this means you are loading the complete file in RAM. (Nowadays 80 MB is not huge anymore but when you encounter a real huge file you will run into troubles.) My advice would be to use "readline()" instead of "readlines()" so each time only one line will be read in RAM.
Like this (untested):
with open("ROTOR_EMR4_BY_R15.cdb", "r") as old_database: # opening files with content manager is good practice as it with open("old_output.txt", "r+") as old_copy: # closes the file automatically at the end of the operations # old_content = old_database.readlines() # this may need a lot of memory for line in old_database.readline(): # line = str(x) # it is already a string print(line) if line.startswith("(3i9,6e21.13e3)"): old_copy.write("EUREKA") else: old_copy.write(line)