gpt4 book ai didi

Python simplejson 坐标问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:40:27 27 4
gpt4 key购买 nike

问题是,在我的笔记本电脑中,我有 python 2.7.5 和一些 Simplejson 版本,而在我的 Debian 6 服务器上,我有 Python 2.6.6 和一些 simplejson 版本..但是在 debian 服务器上发生的事情是 simplejson 为坐标值增加了额外的精度 --

>>> import simplejson as json
>>> streamer_data = json.loads('{"text": "test","geo": {"type": "Point","coordinates": [52.68908263, -8.50845340]},"coordinates": {"type": "Point","coordinates": [-8.50845340, 52.68908263]}}');

>>> print streamer_data
{u'text': test', u'geo': {u'type': u'Point', u'coordinates': [52.689082630000001, -8.5084534000000005]}, u'id': 420024061457346560L, u'coordinates': {u'type': u'Point', u'coordinates': [-8.5084534000000005, 52.689082630000001]}}

在我的笔记本电脑上,这给出了坐标值具有适当精度的正确结果 --

>>> print streamer_data
{'text': 'test', 'geo': {'type': 'Point', 'coordinates': [52.68908263, -8.5084534]}, 'coordinates': {'type': 'Point', 'coordinates': [-8.5084534, 52.68908263]}}

这是 Simplejson 版本控制问题还是其他问题。另请注意,我试图找出 debian 服务器上 simplejson 的版本,但没有成功。

最佳答案

Python 2.6 和 2.7 之间的这种差异与 simplejson 无关。在 2.7 中有 changes to the algorithms used to produce the string representation and rounding of floating point numbers .

$ python2.6 -c "print([52.68908263, -8.50845340])"
[52.689082630000001, -8.5084534000000005]
$ python2.7 -c "print([52.68908263, -8.50845340])"
[52.68908263, -8.5084534]

关于Python simplejson 坐标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20942775/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com