python里面list写成json格式
gain=500,Pot=[0.382996,0.383148,0.38269],Accel=[0.001221,0.000763,0.001068],Fullscale...
gain=500,
Pot=[0.382996,0.383148,0.38269],
Accel=[0.001221,0.000763,0.001068],
Fullscale=282.448
想把他们写入一个TXT文档,打开后的格式应该是这样的{"gain":500,"Pot":[0.382996,0.383148,0.38269],"Accel":[0.001221,0.000763,0.001068],"Fullscale":282.448,}
请问各位大侠,应该怎么写啊?拜托了 展开
Pot=[0.382996,0.383148,0.38269],
Accel=[0.001221,0.000763,0.001068],
Fullscale=282.448
想把他们写入一个TXT文档,打开后的格式应该是这样的{"gain":500,"Pot":[0.382996,0.383148,0.38269],"Accel":[0.001221,0.000763,0.001068],"Fullscale":282.448,}
请问各位大侠,应该怎么写啊?拜托了 展开
2个回答
展开全部
提供一个思路(ps:本思路没有具体实践过,得靠你来完成啦!)
你可以将那几个变量构造成一个json字符串,然后直接写入文件。
all_the_text="{'gain':"+gain+",'Pot':"+Pot+",'Accel':"+Accel+",'Fullscale':"+Fullscale+",}"
python中写入文件的过程如下:
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
你可以将那几个变量构造成一个json字符串,然后直接写入文件。
all_the_text="{'gain':"+gain+",'Pot':"+Pot+",'Accel':"+Accel+",'Fullscale':"+Fullscale+",}"
python中写入文件的过程如下:
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
展开全部
def demo():
data = {}
data['gain'] = 500
data['pot'] = [0.382996,0.383148,0.38269]
data['accel'] = [0.001221,0.000763,0.001068]
data['fullscale'] = 282.448
import json
f = open('data.json', 'w')
json.dump(data, f)
f.close()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询