2

When homebrew downloads software there's this progress bar which is really nice,

######################################################################## 100.0%

I wrote some Python scripts and I run them in the terminal too, and I want to have the same progress bar as the script runs. For example if I have a long for loop I would like to have this progress bar as it runs through the loops. How can I print this progress bar in Python?

LWZ
  • 11,670
  • 22
  • 61
  • 79

1 Answers1

3

You need something like this

import sys
import time

for n in xrange(100):
    time.sleep(1)
    sys.stdout.write("#")
    sys.stdout.flush()

You need to just write out a single "#" and then flush the tty, aka asking the console to pull from stdout and update.

brunsgaard
  • 5,066
  • 2
  • 16
  • 15
  • this is a dublicate.. Note that i am writing it myself. http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console – brunsgaard Oct 09 '14 at 04:18
  • 2
    Thanks for pointing out the duplicate. But this doesn't really do what the OP wants! – senderle Oct 09 '14 at 04:40