pythontranslatepyautogui

Translated object is not iterable


I am trying to make a program that translates whatever you say in Swedish and PyAutoGUI Typewrites it. But when I run the code, I just get the same error.

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')

The error:

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

Can someone pls help me with this?


Solution

  • Error speaks for its self, pyautogui.typewrite() is expecting iterable, for example, string, but you are passing Translated object. You have to explore the way to get text out of your Translated object and only then pass it to pyautogui.