title: ValueError: I/O operation on closed file.
body: <p>Can someone help me out I get this error when I run my file
  ValueError: I/O operation on closed file.
  I am just trying to run a simle test file that says 
  one
  two
  three
  four
  five
  six
  seven
  eight
  nine
  ten</p>
  
  <pre><code>def main():
  # Declare variables
  line = ''
  counter = 0
  
  # Prompt for file name
  fileName = input('Enter the name of the file: ')
  
  # Open the specified file for reading
  infile = open(fileName, 'r')
  
  # Priming read
  line = infile.readline()
  counter = 1
  
  # Read in and display first five lines
  while line != '' and counter &lt;= 5:
  # Strip '\n'
      line = line.rstrip('\n')
      print(line)
      line = infile.readline()
      # Update counter when line is read
      counter +=1  
  
  # Close file
      infile.close()
  
  # Call the main function.
  main()
  </code></pre>