好吧,我遇到一个我无法正确理解的错误。在这种情况下,当我尝试运行Translate()。translate()时,它将引发以下错误。
这是我的代码。我有一个文件lol.txt,它只有3行,每行约6个字。我处理每一行,找到关键字并将其翻译成印地语,然后全部存储在lol2.txt中。
我尝试环顾四周,首先是从googletrans开始,之后出现了py_translate修复的错误。所以我现在在这里。抱歉,有任何错误,我对编码不了解。
from py_translator import Translator
fs = ""
fi =open('lol2.txt','w+',encoding = 'utf-8')
with open('lol.txt') as f:
lines = f.readlines()
count =0
for string in lines:
try:
poop = Translator()
bow = string.split(" ")
final=[]
trans = []
for w in bow:
if(w=='and'):
continue
elif(w[-1:]=="s"):
final.append(w[:-1].lower())
elif(w[-2:]=="es"):
final.append(w[:-2].lower())
else:
final.append(w.lower())
print(final)
for x in final:
trans.append(poop.translate(x,dest='hi').text)
final = trans+final
final_string=""
for f in final:
final_string=final_string+f+", "
fs=fs+final_string[:-2]
count=count+1
except Exception as e:
print(str(e))
continue
fi.write(fs)