Search code examples
pythonpyautogui

Unable to pass variable in typewrite function in python


I have a problem in passing a int variable in typewrite function under pyautogui library consider the example to have clear view

for k in range(13,ag19):        
    pyautogui.typewrite('f-'k)

I want k variable to be auto incremented but it giving the error message


Solution

  • What you probably might need to do is to convert the int to string , as typewrite takes string argument : Refer the below sample :

    import pyautogui
    ag19 = 19
    for k in range(13,ag19):        
        pyautogui.typewrite('f-'+str(k))
    

    And might need to add this in the beginning after import pyautogui :

    pyautogui.PAUSE = 1         # set pyautogui.PAUSE to 1 for a one-second pause after each function call