title: Python: Iterating over .txt file line by line multiple times
body: <p>I have a class which reads a .txt file and performs some various functions to it. I have provided an example of my code below.</p>
  
  <pre><code>class Example(object):
    def __init__(self,fileName):
      self.file = open(fileName)
  
    def function_a(self):
      for line in self.file:
        for char in line:
          #Do some things
  
    def function_b(self):
      for line in self.file:
        for char in line:
          #Do some other things
  </code></pre>
  
  <p>When I create the object and call function_a or function_b everything works perfectly. However, if I call function_b AFTER I call function_a (or vise versa) the first function called works perfect but the second function acts as if self.file is empty. </p>
  
  <p>I can only assume that there is some sort of counter or pointer embedded in self.file that has been activated by my first function and now rests at the end of the file.  As a result when I try to call the second function it picks up where the pointer is and after noticing that there are no more lines left, it returns without any errors.</p>
  
  <p>Assuming that I can not combine function_a and function_b to perform both their actions at the same time, how do I reset self.file so that when I try to iterate through it a second time it will start from the beginning?</p>
  
  <p>Or are my assumptions wrong and is something else going on altogether?</p>