This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients ezio.melotti, fdrake, pitrou, serhiy.storchaka
Date 2013-09-27.11:05:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently pprint.pprint() fails on unencodable characters.

$ LANG=en_US.utf8 ./python -c "import pprint; pprint.pprint('\u20ac')"
$ LANG= ./python -c "import pprint; pprint.pprint('\u20ac')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/", line 56, in pprint
  File "/home/serhiy/py/cpython/Lib/", line 137, in pprint
    self._format(object, self._stream, 0, 0, {}, 0)
  File "/home/serhiy/py/cpython/Lib/", line 274, in _format
UnicodeEncodeError: 'ascii' codec can't encode character '\u20ac' in position 1: ordinal not in range(128)

This is a regression from Python 2 in which repr() always returns ascii string.

$ LANG= python2.7 -c "import pprint; pprint.pprint(u'\u20ac')"

Perhaps pprint() should use the backslashreplace error handler (as sys.displayhook()). With the proposed patch:

$ LANG= ./python -c "import pprint; pprint.pprint('\u20ac')"
Date User Action Args
2013-09-27 11:05:10serhiy.storchakasetrecipients: + serhiy.storchaka, fdrake, pitrou, ezio.melotti
2013-09-27 11:05:10serhiy.storchakasetmessageid: <>
2013-09-27 11:05:10serhiy.storchakalinkissue19100 messages
2013-09-27 11:05:10serhiy.storchakacreate