【发布时间】:2018-12-23 01:27:45
【问题描述】:
我正在尝试通过 textblob 将非英语文本翻译成英语。我阅读了文档并尝试处理如下可能的异常:
txt=" "
for word in text.split():
try:
w=TextBlob(word)
w=w.translate(to='en')
except TranslatorError(TextBlobError):
word=" " #replace word with space
txt=txt+word
except NotTranslated(TextBlobError):
txt=txt+word+" "
else:
txt=txt+w+" "
print(txt)
我收到以下错误:
except TranslatorError(TextBlobError):
NameError: name 'TranslatorError' is not defined
raise NotTranslated('Translation API returned the input string unchanged.')
textblob.exceptions.NotTranslated: Translation API returned the input string unchanged.
我参考了以下链接: https://textblob.readthedocs.io/en/dev/api_reference.html#textblob.exceptions.TextBlobError
我无法解决这些错误。请帮忙!
【问题讨论】:
标签: textblob