Created
September 18, 2014 02:05
-
-
Save SZanlongo/84c7969843defa11205e to your computer and use it in GitHub Desktop.
Progress Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/691946/short-and-useful-python-snippets | |
class ProgressBar(): | |
def __init__(self, width=50): | |
self.pointer = 0 | |
self.width = width | |
def __call__(self, x): | |
# x in percent | |
self.pointer = int(self.width * (x / 100.0)) | |
return "|" + "#"*self.pointer + "-"*(self.width - self.pointer) + \ | |
"|\n %d percent done" % int(x) | |
# Test function (for windows system, change "clear" into "CLS"): | |
if __name__ == '__main__': | |
import time, os | |
pb = ProgressBar() | |
for i in range(101): | |
os.system('clear') | |
print pb(i) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment