标签:
reader(csvfile, dialect=‘excel‘, **fmtparams)
csvfile 支持迭代的对象,file对象或list对象,如果是文件,打开时需要加‘b‘标志参数
dialect 编码风格,默认excel风格(,分隔),dialect支持自定义,通过调用register_dialect方法注册
fmtparam 格式化参数,用来覆盖dialect对象指定的编码风格
程序返回一个 list
import csv with open(‘test.csv‘,‘rb‘) as myfile: lines=csv.reader(myfile) for line in lines: print line
writer(csvfile, dialect=‘excel‘, **fmtparams)
with open(‘t.csv‘, ‘wb‘) as myFile: myWriter=csv.writer(myFile) myWriter.writerow([7,‘g‘]) #一次写一行 myWriter.writerow([8,‘hhh‘]) myList=[[1,2,3],[4,5,6]] myWriter.writerows(myList) #一次写多行
标签:
原文地址:http://my.oschina.net/colben/blog/487503