Created
August 16, 2016 04:56
-
-
Save RyanGWU82/75a434fd256c9cfe807700810f4b5dab to your computer and use it in GitHub Desktop.
Formats DynamoDB API responses so that they're easy to read on screen.
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
from decimal import Decimal | |
from pprint import pprint as _pprint | |
def cleanup(val): | |
if isinstance(val, list): | |
return [cleanup(elem) for elem in val] | |
elif isinstance(val, dict): | |
return dict([(cleanup(k), cleanup(v)) for (k, v) in val.iteritems()]) | |
elif isinstance(val, unicode): | |
return str(val) | |
elif isinstance(val, Decimal): | |
if float(val) % 1.0 == 0.0: | |
return int(val) | |
else: | |
return float(val) | |
else: | |
return val | |
def pprint(val): | |
_pprint(cleanup(val)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment