Skip to content

Instantly share code, notes, and snippets.

@pranavraja
Created August 2, 2012 10:30
Show Gist options
  • Save pranavraja/3236128 to your computer and use it in GitHub Desktop.
Save pranavraja/3236128 to your computer and use it in GitHub Desktop.
Python progress indicator
import os, sys, time
def _term_width():
return int(os.popen('stty size').read().split()[1])
# `progress` is between 0 and 1
def print_progress_update(progress, pipe=sys.stdout):
width = _term_width() - 3
done = int(progress*width)
pipe.write('\r|%s>%s|' % (done*'=',' '*(width-done)))
if __name__ == '__main__':
for i in range(1,11):
print_progress_update(0.1*i)
sys.stdout.flush()
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment