title: How to go through file multiple times in python
body: <p>When I am doing a while loop, I want my code to go through the same file multiple times:</p>
  
  <pre><code>file = open('anyfile.txt', 'r')
  x = 0 
  while x&lt;5:
      for line in file:
          #does stuff
      x = x + 1
  </code></pre>
  
  <p>My code is different, so I have given a simpler piece of code as an example. Whenever I do this, the while loop executes, goes through the file once, and then goes through the while loop till it stops, only going through the file once.
  How do I get my code to run through the file multiple times? The reason for this is because in my actual code I edit he text file in each loop. Please can someone help? </p>