Skip to content

Instantly share code, notes, and snippets.

@diegocostares
Created May 23, 2023 20:04
Show Gist options
  • Save diegocostares/28f7ec9f7fc9f63599bcdabb00a9cf90 to your computer and use it in GitHub Desktop.
Save diegocostares/28f7ec9f7fc9f63599bcdabb00a9cf90 to your computer and use it in GitHub Desktop.
Example from the pprint
import pprint
class MyPrettyPrinter(pprint.PrettyPrinter):
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)
pp = MyPrettyPrinter()
data = { 'name': 'John Doe', 'age': 30, 'city': 'New York' }
pp.pprint(data)
# Output:
# {'age': 30,
# 'city': 'New York',
# 'name': 'John Doe'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment