I am a novice trying to do a simple thing:
read a huge (80 mb of text, around 500000 lines) database file -> make a copy of it while only changing a select portion of it
For this I have the following code, it's not complete yet because it has already run into a problem:
However, the IF statement is never triggered and EUREKA is nowhere to be found.
My suspicion is that before reading Python changes the format of the database, reads it, then before writing, changes it back to the original. So I added the a print command to see what Python "sees" and, fair enough, it doesn't look anything like the original.
I can't possibly paste the whole thing here so I will use screenshots.
![[Image: unknown.png]](https://media.discordapp.net/attachments/197778610885623808/888353201114456124/unknown.png)
This (3i9,6e20.13) is the bit of information I want Python to find and you can clearly see that it's there. It also happens to be the fortran formatting code of the database.
![[Image: unknown.png?width=960&height=483]](https://media.discordapp.net/attachments/197778610885623808/888354531249897472/unknown.png?width=960&height=483)
As you can see, (3i9,6e21.13e3) is nowhere to be found, so of course the IF statement won't trigger!
Would anybody know what formatting python is using and how to change it?
read a huge (80 mb of text, around 500000 lines) database file -> make a copy of it while only changing a select portion of it
For this I have the following code, it's not complete yet because it has already run into a problem:
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() for x in old_content: line = str(x) print(line) if line == "(3i9,6e21.13e3)": old_copy.write("EUREKA") else: old_copy.write(line)The code "works" as the old_output.txt is created and is identical to the original CDB database.
However, the IF statement is never triggered and EUREKA is nowhere to be found.
My suspicion is that before reading Python changes the format of the database, reads it, then before writing, changes it back to the original. So I added the a print command to see what Python "sees" and, fair enough, it doesn't look anything like the original.
I can't possibly paste the whole thing here so I will use screenshots.
![[Image: unknown.png]](https://media.discordapp.net/attachments/197778610885623808/888353201114456124/unknown.png)
This (3i9,6e20.13) is the bit of information I want Python to find and you can clearly see that it's there. It also happens to be the fortran formatting code of the database.
![[Image: unknown.png?width=960&height=483]](https://media.discordapp.net/attachments/197778610885623808/888354531249897472/unknown.png?width=960&height=483)
As you can see, (3i9,6e21.13e3) is nowhere to be found, so of course the IF statement won't trigger!
Would anybody know what formatting python is using and how to change it?