Skip to content

Instantly share code, notes, and snippets.

@sergray
Created June 2, 2012 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergray/2856568 to your computer and use it in GitHub Desktop.
Save sergray/2856568 to your computer and use it in GitHub Desktop.
make pprint speak your language in python console
# assuming you have UTF-8 locale
import pprint
orig_format = pprint.PrettyPrinter._format
def patched_format(self, object, stream, indent, allowance, context, level):
if isinstance(object, unicode):
stream.write("u\'")
stream.write(object.encode('utf8'))
stream.write("'")
else:
orig_format(self, object, stream, indent, allowance, context, level)
pprint.PrettyPrinter._format = patched_format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment