翻译后的对象不可迭代

Translated object is not iterable

我正在尝试制作一个程序来翻译您用瑞典语说的任何内容,然后 PyAutoGUI 将其打字。但是当我 运行 代码时,我得到了同样的错误。

trans=Translator()
translating_text=input('Enter text to translate into  S w e d i s h:')
t=trans.translate(translating_text,src='en',dest='sv')
time.sleep(5)
translated=t
pyautogui.typewrite(translated)
pyautogui.press('enter')

错误:

Traceback (most recent call last):
   File "C:\Users\admin\Documents\Python Projects\CrendlePy.py", line 56, in <module>
   ahm_swedish()
   File "C:\Users\admin\Documents\Python Projects\CrendlePy.py", line 54, in ahm_swedish
   pyautogui.typewrite(translated)
   File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site- 
   packages\pyautogui\__init__.py", line 586, in wrapper
   returnVal = wrappedFunction(*args, **kwargs)
   File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site- 
   packages\pyautogui\__init__.py", line 1665, in typewrite
       for c in message:
  TypeError: 'Translated' object is not iterable

有人可以帮我解决这个问题吗?

错误不言自明,pyautogui.typewrite() 期望可迭代,例如字符串,但您传递的是 Translated 对象。 您必须探索从 Translated 对象中获取文本的方法,然后才将其传递给 pyautogui。