Python reset line in for loop

前端 未结 2 640
旧时难觅i
旧时难觅i 2021-01-27 13:02

I\'m trying to repeatedly go through a text file of a few lines. When my for loop is done with one pass through the file, I want to repeat the file from the beg

2条回答
  •  遥遥无期
    2021-01-27 13:56

    When you read the file, a pointer is set to the end of the file. To go back to the beginning of the file you reset the pointer by doing "infile.seek(0)" If you want to go to the end of the file you pass 2 as the argument.

提交回复
热议问题