-
-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Description
Description
I'm trying to use a unicode string as a marker in both python 2 and 3. In python 3 this works fine, but in python 2 I get the following error (Full trace at the end):
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-24: ordinal not in range(128)
Using encode('utf-8') on this marker results in the error: AssertionError: Markers are required to be 1 char
The trace shows that the string, which is already unicode, is being encoded into unicode again. Perhaps this is superfluous?
Should I call bar in a different way?
Code
import progressbar
from progressbar import Bar
widgets = [Bar(marker=u'\u2588')]
progress_bar = progressbar.ProgressBar(
max_value=10, widgets=widgets)
progress_bar.start()
progress_bar.update(1)Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/bar.py", line 550, in update
StdRedirectMixin.update(self, value=value)
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/bar.py", line 143, in update
DefaultFdMixin.update(self, value=value)
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/bar.py", line 48, in update
self.fd.write('\r' + self._format_line())
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/bar.py", line 481, in _format_line
widgets = ''.join(self._format_widgets())
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/bar.py", line 472, in _format_widgets
widget_output = widget(self, data, portion)
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/widgets.py", line 669, in __call__
marker = converters.to_unicode(self.marker(progress, data, width))
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/python_utils/converters.py", line 178, in to_unicode
input_ = input_.decode(encoding, errors)
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15: ordinal not in range(128)
import progressbar
from progressbar import Bar
widgets = [Bar(marker=u'\u2588'.encode('utf-8'))] File "<stdin>", line 1, in <module>
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/widgets.py", line 655, in __init__
self.marker = create_marker(marker)
File "/home/bweel/anaconda2/envs/boatswain2/lib/python2.7/site-packages/progressbar/widgets.py", line 40, in create_marker
assert len(marker) == 1, 'Markers are required to be 1 char'
AssertionError: Markers are required to be 1 char
Versions
- Python version:
2.7.12 | packaged by conda-forge | (default, Sep 8 2016, 14:22:31) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] - Python distribution/environment:
Anaconda - Operating System:
Ubuntu Linux (Mint) - Package version:
3.16.1
Metadata
Metadata
Assignees
Labels
No labels