Advertisement
Guest User

Untitled

a guest
Jan 18th, 2014
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import functools
  2. from decimal import Decimal
  3. from json import JSONEncoder
  4.  
  5. def wrap_default(real_default):
  6.     @functools.wraps(real_default)
  7.     def wrapper(self, obj):
  8.         if isinstance(obj, Decimal):
  9.             return float(obj)
  10.         return real_default(self, obj)
  11.     return wrapper
  12.  
  13. JSONEncoder.default = wrap_default(JSONEncoder.default)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement