-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressBar.py
29 lines (24 loc) · 956 Bytes
/
ProgressBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
class ProgressBar:
def __init__(self,total,barlength=50,symbol = "#"):
self.total = total
self.barlength = barlength
self.symbol = symbol
self.counter = 0
self.lastcounter = 0
def update(self):
if self.counter > self.total:
self.reset()
self.counter += 1
if float(self.counter - self.lastcounter)/self.total >= 0.01:
percent = float(self.counter) / self.total
hashes = self.symbol * int(round(percent * self.barlength))
spaces = ' ' * (self.barlength - len(hashes))
sys.stdout.write("\rPercent: [{0}] {1}%".format(hashes + spaces, int(round(percent * 100))))
sys.stdout.flush()
self.lastcounter = self.counter
if self.counter == self.total:
sys.stdout.write("\n")
self.reset()
def reset(self):
self.counter = 0