title: Python class method output different each time
body: <p>Suppose I have a text file called 'text.txt' which contains:</p>
  
  <pre><code>Apple
  Orange
  Strawberry
  </code></pre>
  
  <p>Total of 3 lines and I have a class:</p>
  
  <pre><code>class ReadTextFile:
    def __init__(self, filename):
      self.filename = (open(filename, 'r'))
  
    def number_of_lines(self):
      num = 0
  
      for line in self.filename:
        line = line.strip("\n")
        num += 1
  
      return(num)
  </code></pre>
  
  <p>When I use this class to count the total number of lines, on the first try it gives me a correct answer which is '3', but after that it gives me '0' unless I redefine the variable "text":</p>
  
  <pre><code>&gt;&gt;&gt; text = ReadTextFile('text.txt')
  &gt;&gt;&gt; text.number_of_lines()
  3
  &gt;&gt;&gt; text.number_of_lines()
  0
  &gt;&gt;&gt; text.number_of_lines()
  0
  ...
  &gt;&gt;&gt; text = ReadTextFile('text.txt')
  &gt;&gt;&gt; text.number_of_lines()
  3
  &gt;&gt;&gt; text.number_of_lines()
  0
  ...
  </code></pre>
  
  <p>What am I doing wrong here?</p>