csv打开文件的时候,如下代码,出错:
import csv name = "D:\selenium\data\name.csv" inf= csv.reader(open(name,"rb")) for i in inf: print(i)
修改为:
import csv name = "D:\selenium\data\name.csv" inf= csv.reader(open(name,"r")) for i in inf: print(i)
或者
import csv name = "D:\selenium\data\name.csv" inf= csv.reader(open(name,"rt")) for i in inf: print(i)
或者
import csv name = "D:\selenium\data\name.csv" with open (name,"r") as f: inf=csv.reader(f) for i in inf: print(i)
顺便写一个写入csv的方法:
import csv name = "D:\selenium\data\name2.csv" with open (name,"w") as f: ss=csv.writer(f) ss.writerow(["sss","124"]) #括号里面是个list