-
-
Notifications
You must be signed in to change notification settings - Fork 103
Closed
Description
Description
I prefered to use DynamicMessage instead of FormatCustomText because it's easier to set up.
so I added a DynamicMessage widget and update its value with a string, and I get an error that the g format code doesn't work with an str
ValueError: Unknown format code 'g' for object of type 'str'
Code
import progressbar, time
widgets = [
progressbar.Percentage(),
progressbar.Bar(),
progressbar.DynamicMessage('user'),
]
with progressbar.ProgressBar(max_value=100, widgets=widgets) as bar:
for i in range(100):
bar.update(i, user='me')
time.sleep(0.2)`Versions
- Python version: 3.7.3 (default, Mar 26 2019, 21:43:19)
[GCC 8.2.1 20181127] - Python distribution/environment: CPython
- Operating System: Antergos (Arch Linux)
- Package version: 3.39.3
Solution
In order to fix it I changed the code of function call of DynamicMessage like this
def __call__(self, progress, data):
val = data['dynamic_messages'][self.name]
if val:
if isinstance(val,str):
return self.name + ': ' + '{:6s}'.format(val)
else:
return self.name + ': ' + '{:6.3g}'.format(val)
else:
return self.name + ': ' + 6 * '-'Metadata
Metadata
Assignees
Labels
No labels