Search code examples
pythonpyautogui

pyauto gui TypeError: 'int' object is not iterable


Here is my code:

import pyautogui, time, random
time.sleep(5)
integer = random.randint(1, 1000)
while True:
    pyautogui.typewrite(integer)
    pyautogui.press("enter")
    pyautogui.sleep(10)

Here is the error message:

TypeError: 'int' object is not iterable

I am basically trying to print a random integer. Could somebody please help me with this? Thank you so much.


Solution

  • I think typewrite() is expecting a string. Try pyautogui.typewrite(str(integer)) instead.

    This works. Thank you so much. I have one problem -- It is printing the exact same number every time (110).

    If you re-run the program then it should be a different number. If you want a new number every loop, then you should put the integer = random.randint(1, 1000) line inside the loop to be repeated instead of just doing it once before looping.