[英]Translation error while using python package "googletrans"
code is here代码在这里
import openpyxl
from googletrans import Translator
loc = r"C:\Users\userid\Desktop\translation.xlsx"
gs = Translator.translate()
wb = openpyxl.load_workbook(loc)
sheet = wb.active
for i in range(2, sheet.max_row + 1):
original = sheet.cell(row=i, column=1).value
translated = gs.translate(original, 'de')
sheet.cell(row=i, column=2).value = translated
wb.save(loc)
Error:错误:
Traceback (most recent call last):
File "c:\Users\userid\translation.py", line 8, in <module>
gs = Translator.translate()
TypeError: translate() missing 2 required positional arguments: 'self' and 'text'
You're trying to use the function translate()
with the Translator
class itself, not an instance of it.您正在尝试将 function
translate()
与Translator
class 本身一起使用,而不是它的一个实例。
Try:尝试:
gs = Translator()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.