title: Python print statement prints nothing with a carriage return
body: <p>I'm trying to write a simple tool that reads files from disc, does some image processing, and returns the result of the algorithm. Since the program can sometimes take awhile, I like to have a progress bar so I know where it is in the program. And since I don't like to clutter up my command line and I'm on a Unix platform, I wanted to use the '\r' character to print the progress bar on only one line.</p>
  
  <p>But when I have this code here, it prints nothing.</p>
  
  <pre><code>
  # Files is a list with the filenames
  for i, f in enumerate(files):
      print '\r%d / %d' % (i, len(files)),
      # Code that takes a long time
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>
  print '\r', i, '/', len(files),
  </code></pre>
  
  <p>Now just to make sure this worked in python, I tried this:</p>
  
  <pre><code>
  heartbeat = 1
  while True:
      print '\rHello, world', heartbeat,
      heartbeat += 1
  </code></pre>
  
  <p>This code works perfectly. What's going on? My understanding of carriage returns on Linux was that it would just move the line feed character to the beginning and then I could overwrite old text that was written previously, as long as I don't print a newline anywhere. This doesn't seem to be happening though.</p>
  
  <p>Also, is there a better way to display a progress bar in a command line than what I'm current trying to do?</p>