I have a spanish novel, in a plain textfile, and I want to make a Python script that puts a translation in brackets after difficult words. I have a list of the words (with translations) I want to do this with in a separate text file, which I have tried to format correctly. I ve forgotten everything I knew about Python, which was very little to begin with, so I m struggling. This is a script someone helped me with:
bookin = (open("C:UsersKing KongDocuments\_div_tekstfiler_coc_es.txt")).read()
subin = open("C:UsersKing KongDocuments\_div_tekstfiler_cocdict.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("fileout.txt", "w")
bookout.write(bookin)
bookout.close()
当我这样做时,我发出这一错误信息:
Traceback (most recent call last):
File "C:Python27 ranslscript_secver.py", line 4, in <module>
ogword, meaning = line.split()
ValueError: too many values to unpack
新颖的粗金字大,一根字典由大约1 000个关键价值奶粉组成。
Does this mean there s something wrong with the dictionary? Or it s too big? Been researching this a lot, but I can t seem to make sense of it. Any advice would be appreciated.