首页 > 代码库 > Python168的学习笔记5
Python168的学习笔记5
关于对csv文件的操作。
python标准库中有csv的库,使用非常方便。
1 import csv 2 3 with open(‘pingan.csv‘,‘rb‘) as rf: 4 reader = csv.reader(rf)#读操作 5 with open(‘pingan2.csv‘,‘wb‘) as wf: 6 writer = csv.writer(wf) 7 headers = reader.next() 8 writer.writerow(headers)#写操作 9 for row in reader: 10 if row[0] < ‘2016-01-01‘:#满足条件就退出循环 11 break 12 if int(row[5]) >= 50000000:#对特定数据的判断 13 writer.writerow(row)
关于对json文件的操作。
python标准库中也有json的库,操作也很方便。
1 import json 2 3 l = (1,2,‘abc‘,{‘name‘:‘john‘,‘age‘:18}) 4 5 with open(‘demo.json‘,‘wb‘) as f: 6 json.dump(l,f) 7 8 with open(‘demo.json‘,‘rb‘) as f: 9 r = json.load(f)
Python168的学习笔记5
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。