Skip to content

Instantly share code, notes, and snippets.

@RyanGWU82
Created August 16, 2016 04:56
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 RyanGWU82/75a434fd256c9cfe807700810f4b5dab to your computer and use it in GitHub Desktop.
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.
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