Search code examples
pythonasciipyautogui

I want to make a random numbers and letters generator, but this will not work


import random, string, pyautogui, time
numbers=random.randint(1000000000, 1000000000000)
def random_char(y):
       return ''.join(random.choice(string.ascii_letters) for x in range(y))

time.sleep(2)
pyautogui.typewrite(random_char(10))
time.sleep(0.5)
pyautogui.write(numbers)

output = piTPLlrXPn (<--- Random 10 Letters)

but numbers won't work

Error:

Exception has occurred: TypeError
'int' object is not iterable
  File "C:\Users\Noah\Pictures\Python\test.py", line 9, in <module>
    pyautogui.write(numbers)

EDIT: Works Now! Thanks for the help!


Solution

  • pyautogui.write() expects a iterable object, ints are not iterable but strings are so in this case you just need to call,

    pyautogui.write(str(numbers))
    

    And that should write the random number you got at the start of your code.

    However you could do something similar to what you are doing with ascii characters giving a list of int characters or you could extend the list of ascii characters with numbers if you want a result with letters and numbers