Created
April 25, 2017 02:30
-
-
Save priancho/a2a45be370d24bc861ac0e806300a2aa to your computer and use it in GitHub Desktop.
python 2.x pprint with UTF-8 text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
class MyPrettyPrinter(pprint.PrettyPrinter): | |
"""PrettyPrint with UTF-8 text. | |
Refer to: http://stackoverflow.com/questions/10883399/unable-to-encode-decode-pprint-output | |
""" | |
def format(self, object, context, maxlevels, level): | |
if isinstance(object, unicode): | |
return (object.encode('utf8'), True, False) | |
return pprint.PrettyPrinter.format(self, object, context, maxlevels, level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment