I'm ashamed to resort to asking for help again, but I'm stuck.
I have a spanish novel (in plain text), and I have a Python script that's supposed to put translations for difficult words in parentheses, using a custom dictionary in another text file.
After a lot of trial and error, I've managed to have the script run, and write the novel to a new text file as it's supposed to do.
Only problem is, no changes have been made to the text in the novel, that is, the translations haven't been inserted into the text. The dictionary is a plain text file, and it's formatted like this:
[spanish word] [english translation]
[spanish word] [english translation]
and so on. Note that the words isn't really enclosed in brackets. There's a single space between each word, and there isn't spaces anywhere else in the file.
Here's the offending code:
bookin = (open("novel.txt")).read()
subin = open("dictionary.txt")
for line in subin.readlines():
ogword, meaning = line.split(" ")
subword = ogword + "(meaning)"
bookin.replace(ogword, subword)
ogword = ogword.capitalize()
subword = ogword + "(meaning)"
bookin.replace(ogword, subword)
subin.close()
bookout = open("output.txt", "w")
bookout.write(bookin)
bookout.close()
Advice would be greatly appreciated.
Edit: The MemoryError is solved now, there were errors in the dictionary I thought I'd fixed. Thank you so much to those who helped me with this stupid problem!