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("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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值