-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathstep5.py
More file actions
32 lines (25 loc) · 734 Bytes
/
Copy pathstep5.py
File metadata and controls
32 lines (25 loc) · 734 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
"""Add `redirect_stdout=True` so a stray `print()` doesn't corrupt the bar.
Anything printed from inside the loop is held back and flushed above the
bar on its next redraw, instead of colliding with the bar's own carriage
return.
"""
import time
import progressbar
def main() -> None:
widgets = [
progressbar.Percentage(),
' ',
progressbar.Bar(),
' ',
progressbar.ETA(),
]
with progressbar.ProgressBar(
max_value=100, widgets=widgets, redirect_stdout=True
) as bar:
for i in range(100):
time.sleep(0.01)
if i % 25 == 0:
print(f'Reached step {i}')
bar.update(i + 1)
if __name__ == '__main__':
main()