blob = TextBlob("hello")
blob.translate(from_lang='en', to='fr')
这是输出结果
TextBlob("bonjour")
看起来它已经被弃用,并建议使用官方的 Google Translate API:
0.16.0(2020年4月26日)弃用:
TextBlob.translate() 和 TextBlob.detect_language 已被弃用。改用官方的 Google Translate API (#215)。其他更改:
不向后兼容: 不再支持 Python 3.4。支持 Python 3.7 和 Python 3.8。在 Python 2 上针对 nltk<3.5 进行测试 (#315)。
您可以在该库的新版本中找到这样的警告: '''使用 Google 的 Translate API 将单词翻译成另一种语言。
.. deprecated:: 0.16.0
Use the official Google Translate API instead.
.. versionadded:: 0.5.0
'''
看起来谷歌会阻止请求并要求解决验证码: https://github.com/sloria/TextBlob/issues/215