title: Python File Close on Program Exit
body: <p>If I wanted to close a file in a program with an infinite loop, I could do the following:</p>
  
  <pre><code>file = open('abc', 'w')
  
  while True:
      try:
          file.write('a\n')
      except KeyboardInterrupt:
          break
  
  file.close()
  </code></pre>
  
  <p>But if I just left it like this:</p>
  
  <pre><code>file = open('abc', 'w')
  
  while True:
      file.write('a\n')
  </code></pre>
  
  <p>Would the file not get closed on exit?</p>