Retardrino
Retardrino

Reputation: 63

How to make readline go to the second line every loop

I don't really know how to code I just want to make this script with pyautogui and I want to know how to loop all my code and change my readline each loop

import pyautogui
import time
import pyperclip

time.sleep(4)

list = open(r'C:\Users\PC\Desktop\list.txt')
firstItem = list.readline() #how do I make this read second line and then loop it for changing everytime
pyperclip.copy(firstItem) #This copies the first line I want to know how to make it loop and copy the second line when this script is finished and then the 3rd when it's finished etc 
pyautogui.hotkey('alt', 'tab') 
pyautogui.moveTo(1008, 174) 
pyautogui.click(clicks = 3)
pyautogui.typewrite(pyperclip.paste()) #pastes the first item into the text box
pyautogui.moveTo(1354,241, duration=3) 
pyautogui.click(clicks=1)
time.sleep(2)
pyautogui.click(clicks=2) 
pyautogui.moveTo(1345,502, duration=0.15)
pyautogui.click()
pyautogui.moveTo(1522,281, duration=0.15)
pyautogui.click ()
pyautogui.moveTo(1372,385)

Upvotes: 0

Views: 295

Answers (2)

ofthegoats
ofthegoats

Reputation: 295

If you just want to read through the whole file line by line, I would suggest using a for loop, as well as readlines() instead of readline().
readlines(), unlike readline(), will return all the lines of the file in an array, with each line in a separate index.

file = open(filepath)
list = file.readlines()
for i in list:
    pyperclip.copy(i)
    #rest of script...

Upvotes: 1

new-dev-123
new-dev-123

Reputation: 411

call readline() again to read the next line.

If you want to read all the lines until the file is exhausted you need to loop like so:

with open(filepath) as fp:  
    line = fp.readline()
    while line:
       line = fp.readline()

Upvotes: 0

Related Questions