码迷,mamicode.com
首页 > 编程语言 > 详细

python 写数据到txt 文件

时间:2017-06-03 22:36:23      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:表示   obd   event   imp   cat   utf-8   sub   emerge   location   

# 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("main.txt",‘w‘,‘utf-8‘)


#f.write(str(list))
for i in list:
    f.write(str(i)+‘\n‘)  #\n为换行符

f.close()

  

python数组写入txt

 

 

 
#coding=utf-8
import codecs

list = [[1,2],[3,4]]

s = u‘亚像素精度:\r\n‘  #u表示读取中文,\r\n为换行符
f = codecs.open("main.txt",‘w‘,‘utf-8‘)

f.write(s)
#f.write(str(list))
for i in list:
    f.write(str(i)+‘\r\n‘)  #\r\n为换行符

f.close()

  

 

python 写数据到txt 文件

标签:表示   obd   event   imp   cat   utf-8   sub   emerge   location   

原文地址:http://www.cnblogs.com/saryli/p/6938536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!