title: python print function in real time
body: <p>I recently switched OS and am using a newer Python (2.7). On my old system, I used to be able to print instantaneously. For instance, suppose I had a computationally intense for loop:</p>
  
  <pre><code>for i in range(10):
    huge calculation
    print i
  </code></pre>
  
  <p>then as the code completed each iteration, it would print <code>i</code></p>
  
  <p>However, on my current system, python seems to cache the stdout so that the terminal is blank for several minutes, after which it prints:</p>
  
  <pre>
  1
  2
  3
  </pre>
  
  <p>in short succession. Then, after a few more minutes, it prints:</p>
  
  <pre>
  4
  5
  6
  </pre>
  
  <p>and so on. How can I make python print as soon as it reaches the <code>print</code> statement?</p>