python怎么把数据写进txt_python写数据到txt⽂件
# coding=utf-8
import codecs
# list = [[1,2],[3,4]]
list = ['{"PN":"34VT123","DUID":"XXXX","location":{"coordinates":[-100.35256443,33.4586858]},"SPD":125,"DT":"2017-06-02T13:15:20Z","driverID":"XXXXX","cate":"event","subCate":"OBDII","eventOBDII": {"what":"emergencyBrake","param":2,"GID":123456479}}','{"PN":"34VT123","DUID":"XXXX","location":{"coordinates":[-
100.35256443,33.4586858]},"SPD":125,"DT":"2017-06-
03T13:15:20Z","driverID":"XXXXX","cate":"event","subCate":"OBDII","eventOBDII": {"what":"emergencyBrake","param":2,"GID":123456479}}']
f = codecs.open("",'w','utf-8')
#f.write(str(list))
for i in list:
f.write(str(i)+'\n') #\n为换⾏符
f.close()
python数组写⼊txt
#coding=utf-8python怎么读取txt
import codecs
list = [[1,2],[3,4]]
s = u'亚像素精度:\r\n' #u表⽰读取中⽂,\r\n为换⾏符
f = codecs.open("",'w','utf-8')
f.write(s)
#f.write(str(list))
for i in list:
f.write(str(i)+'\r\n') #\r\n为换⾏符
f.close()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论