the line : with open('new%s.txt' % intg ,'a') as g : is giving error in below code. Every time I call the function "Repeat", it should create file with name new1.txt, new2.txt and so on. But it is giving error : "name 'intg' is not defined" I want dynamic name for screenshot file and txt file, to prevent overwriting of file. The code is for selecting data from a software, copying it, and pasting it in new file each time. Please help:
import win32api
import win32com.client
import pyautogui
import pyperclip
shell = win32com.client.Dispatch("WScript.Shell")
win32api.Sleep(5000)def repeat( intg ):import pyautoguipyautogui.moveTo(17, 213)win32api.Sleep(2000)pyautogui.screenshot('%s.png' % intg)pyautogui.click()win32api.Sleep(2000)pyautogui.hotkey('ctrl', 'c')s = pyperclip.paste() win32api.Sleep(2000)with open('new%s.txt' % intg ,'a') as g:g.write(s)print("done")repeat( intg = 1 )
repeat( intg = 2 )win32api.Sleep(5000)
print ("done")