I am ashamed to resort to help again, but I am stuck.
I have a Spanish novel (in plain text), and I have a Python script that should put translations for complex words in parentheses using a custom dictionary in another text file.
After a lot of trial and error, I managed to run the script and write the novel in a new text file, as it should have done.
The only problem is that the text in the novel was not entered, i.e. translations were not added to the text. A dictionary is a simple text file that is formatted as follows:
[spanish word] [english translation]
[spanish word] [english translation]
etc. Please note that words are not enclosed in brackets. There is one space between each word, and there is no place in it elsewhere.
Here's the abusive 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()
.
: MemoryError , , , , . , !