-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathvariable.py
More file actions
37 lines (28 loc) · 902 Bytes
/
Copy pathvariable.py
File metadata and controls
37 lines (28 loc) · 902 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
"""``Variable`` displays a live, named value with custom formatting.
Reach for it to track a value that is not the bar's own progress -- a
loss, a learning rate, a username -- updated via
``bar.update(name=value)``. Compare ``Postfix`` for several values
rendered together as one compact suffix, and ``DynamicMessage`` for the
original name of this same widget.
"""
import random
import time
import progressbar
random.seed(0)
STEPS = 24
def main() -> None:
widgets = [
progressbar.Percentage(),
' ',
progressbar.Bar(),
' ',
progressbar.Variable('loss'),
]
with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
loss = 1.0
for step in range(STEPS):
loss *= 0.9 + random.random() * 0.05
bar.update(step + 1, loss=loss)
time.sleep(0.005)
if __name__ == '__main__':
main()