我有一个(编写得很糟糕的)ifs和elses的长函数以及包含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)吗?
(很明显,它有印刷品的地方:“脚本有些东西!”,我有很多带有时间戳的杂乱的东西...)
答案 0 :(得分:3)
"让循环回到第1行文件"
是的,您需要调用搜索功能才能返回到您想要的线路。
fileobject.seek(0)
这将返回该特定文件的第1行。