Skip to content

Instantly share code, notes, and snippets.

@wpjunior
Created February 5, 2014 12:10
Show Gist options
  • Save wpjunior/8822393 to your computer and use it in GitHub Desktop.
Save wpjunior/8822393 to your computer and use it in GitHub Desktop.
terminal progressbar
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Wilson Pinto Júnior <[email protected]>
#
import time
import sys
def print_in_line(text):
sys.stdout.write(text)
sys.stdout.write('\r')
sys.stdout.flush()
def print_progressbar(value, text=None):
inner = ('#' * (i / 4)).ljust(25, '_')
if text:
print_in_line("%s [%s] %d %%" % (text, inner, i))
else:
print_in_line("[%s] %d %%" % (inner, i))
for i in xrange(101):
print_progressbar(i, "Testing")
time.sleep(0.05)
print "\nFinished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment