Message176135
In 2.7 and other versions, the json module has incomplete support for decimals:
>>> json.loads('0.2', parse_float=Decimal)
Decimal('0.2')
>>> json.dumps(json.loads('0.2', parse_float=Decimal))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 201, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 178, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: Decimal('0.2') is not JSON serializable
simplejson encodes decimals out of the box, but json can’t round-trip. |
|
Date |
User |
Action |
Args |
2012-11-22 22:45:38 | eric.araujo | set | recipients:
+ eric.araujo, rhettinger, pitrou, ezio.melotti |
2012-11-22 22:45:38 | eric.araujo | set | messageid: <1353624338.46.0.574343718645.issue16535@psf.upfronthosting.co.za> |
2012-11-22 22:45:38 | eric.araujo | link | issue16535 messages |
2012-11-22 22:45:37 | eric.araujo | create | |
|