[英]Translation error while using python package "googletrans"
代碼在這里
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)
錯誤:
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'
您正在嘗試將 function translate()
與Translator
class 本身一起使用,而不是它的一個實例。
嘗試:
gs = Translator()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.