-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressBar.py
More file actions
42 lines (30 loc) · 960 Bytes
/
progressBar.py
File metadata and controls
42 lines (30 loc) · 960 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
import sys
'''
Progress Bar
Parameters: width = number of iterations
'''
class progressBar():
''' Init function '''
def __init__(self, width):
if width is None:
self.width = 40
else:
self.width = width
sys.stdout.write("[%s]" % (" " * self.width))
sys.stdout.flush()
sys.stdout.write("\b" * (self.width+1)) # return to start of line, after '['
self.iter = 0
''' Update function > use this inside for loops '''
def update(self):
sys.stdout.write("-")
sys.stdout.flush()
self.iter = self.iter + 1
if self.iter == self.width:
sys.stdout.write("]\n") # this ends the progress bar
if __name__ == '__main__':
pBar = progressBar(40)
for i in range(pBar.width):
time.sleep(0.1) # do real work here
# update the bar
pBar.update()