我正在读一个文件,想知道是否有办法在for循环中读取下一行?
我目前正在阅读这样的文件:
file = open(input,"r").read()
for line in file.splitlines():
line = doSomething()
Run Code Online (Sandbox Code Playgroud)
那么无论如何我可以在for循环中检索文件的下一行,这样我就可以在doSomething()函数中执行一些操作了吗?
谢谢
该脚本针对accounts.txt文件中存在的帐户数运行.无论accounts.txt文件中有多少个帐户,我都希望运行脚本x次.所以我只输入一个输入10,脚本应该只运行for循环10次.以下是我的代码.
有人可以请帮助我如何修复for循环或为for循环添加新的父级?
file = open('accounts.txt','r')
for line in file:
credentials = line.split(";")
username = credentials[0]
password = credentials[1]
comment = credentials[2]
chromedriver = "/Users/Ali/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
# driver = webdriver.Chrome(chromedriver)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--mute-audio")
Run Code Online (Sandbox Code Playgroud) 我有一个包含数千条记录的文件,每行一条.我需要阅读100,处理它们,读取另外100个,处理它们等等.我不想加载那些记录并将它们保存在内存中.如何使用Python从打开的文件读取(直到EOF)100或更少(当遇到EOF时)行?