我使用TextBlob运行语言转换器。它可以从字符串翻译过来。但是,我尝试为数据帧中的数据循环textblob转换器,而数据帧中的数据可能混合了不同的语言(en和es)。你知道吗
我使用的代码是:
for content in data:
blob = TextBlob(content)
for i in data:
blob = TextBlob(i)
blob.translate(from_lang = 'en', to = 'es')
错误是:
83 result = result.encode('utf-8')
84 if result.strip() == source.strip():
---> 85 raise NotTranslated('Translation API returned the input string unchanged.')
86
87 def _request(self, url, host=None, type_=None, data=None):
NotTranslated: Translation API returned the input string unchanged.
因为没有必要在每种情况下“en”和“es”必须不同。在许多情况下,“es”和“en”具有相同的文本。所以在两者相同的情况下会出现错误。使用try-and-catch语句将处理所有具有相同文本的情况,最终使代码正常工作。你知道吗
相关问题 更多 >
编程相关推荐