【发布时间】:2019-06-01 00:34:09
【问题描述】:
我想保存在键上有元组的字典。
我试过pickle、ujson、json来保存字典。所有这些都不起作用。
字典有:
dictionary = {(-30, -29, -72, -71): [[-29.99867621124457, -71.75349423197208, 220], [-29.996964568219873, -71.7521560207641, 220], [-29.99696437241995, -71.7507330056961, 220], [-29.99761665426199, -71.75016101067708, 220]]}
我试过了:
with open('depth_echo.txt', 'w') as file:
file.write(ujson.dumps(dictionary)
import json
a, b, c = "abc"
data = {(1,2,3):(a,b,c), (2,6,3):(6,3,2)}
on_disk = json.dumps(data.items())
【问题讨论】:
-
ujson是外部库吗? -
我已为您的问题添加了答案。我敢打赌你没有正确使用
ujson,因为我刚试过,效果很好。
标签: python dictionary save tuples