title: How come a file doesn't get written until I stop the program?
body: <p>I'm running a test, and found that the file doesn't actually get written until I control-C to abort the program.  Can anyone explain why that would happen?</p>
  
  <p>I expected it to write at the same time, so I could read the file in the middle of the process.</p>
  
  <pre><code>import os
  from time import sleep
  
  f = open("log.txt", "a+")
  i = 0
  while True:
    f.write(str(i))
    f.write("\n")
    i += 1
    sleep(0.1)
  </code></pre>