Created
May 23, 2023 20:04
-
-
Save diegocostares/28f7ec9f7fc9f63599bcdabb00a9cf90 to your computer and use it in GitHub Desktop.
Example from the pprint
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): | |
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