python-如何在for循环中更改为另一行文件
作者:互联网
我有一个ifs和elses(不写)长函数,而whatnot包含一个for循环,用于在文件的每一行中查找:
def check(low,high):
with open('users.txt', 'r+') as followed:
ts = time.time()
sttime = datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S - ')
done_checking = open('done_checking.txt', "a")
done = 0
skippers = 0
max_tries = 15
for line in followed:
if skippers==30:
print "MAKE THE FOR LOOP GO BACK TO LINE 1 OF FILE"
else:
print "Does some other stuff"
if done==max_tries:
sleep(randint(850,1150))
done = 0
elif:
print: "SCRIPT DOES SOME STUFF!"
else:
skippers += 1
print: "SCRIPT HAS SKIPPED A USER"
有没有办法说
“使循环回到文件的第1行”
我可以将for循环重置为要检查的文件的第一行(users.txt)吗?
(显然,它的打印内容是:“ SCRIPT DOESS SOME STUFF!”,我在时间戳上发生了很多混乱的事情……)
解决方法:
“MAKE THE FOR LOOP GO BACK TO LINE 1 OF FILE”
是的,您需要调用seek函数返回所需的行.
fileobject.seek(0)
这将返回到该特定文件的第1行.
标签:for-loop,python 来源: https://codeday.me/bug/20191120/2045921.html