如何使readline在每个循环中转到第二行

时间:2019-07-04 15:06:37

标签: python python-3.x

我真的不知道如何编码,我只是想用pyautogui编写此脚本,我想知道如何循环所有代码并在每次循环中更改我的阅读行

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)

2 个答案:

答案 0 :(得分:1)

如果您只想逐行阅读整个文件,建议您使用for循环以及"no-host-metadata-property": false 而不是readlines()
readline()readlines()不同,它将返回数组中文件的所有行,并且每一行都在单独的索引中。

readline()

答案 1 :(得分:0)

再次调用readline()以读取下一行。

如果要读取所有行,直到文件用完,则需要像这样循环:

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