[issue9779] argparse.ArgumentParser not support unicode in print help

Steven Bethard report at bugs.python.org
Mon Sep 13 11:08:55 CEST 2010


Steven Bethard <steven.bethard at gmail.com> added the comment:

Are you sure this is an argparse issue, and not a terminal issue? Here's what I see:

>>> parser = argparse.ArgumentParser(description=u'Rus Рус')
>>> print(parser.description)
Rus Рус
>>> sys.stderr.write(parser.description)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-6: ordinal not in range(128)
>>> parser.format_help()
u'usage: [-h]\n\nRus \u0420\u0443\u0441\n\noptional arguments:\n  -h, --help  show this help message and exit\n'
>>> sys.stderr.write(parser.format_help())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 17-19: ordinal not in range(128)

To me, it looks like sys.stderr doesn't like the unicode, even though at the interactive prompt I can print things okay.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9779>
_______________________________________


More information about the Python-bugs-list mailing list