读取csv的文件信息


with codecs.open(filename, mode, 'gb2312') as f:

reader = csv.reader()
y = list(reader)
x = y[0]
    print len(x)列数, len(y)行数

mode:

r :  仅读,待打开的文件必须存在
w:  仅写,若文件已存在,内容将先被清空
a:   仅写,若文件已存在,内容不会清空
r+:  读写,待打开的文件必须存在
w+: 读写,若文件已存在,内容将先被清空
a+ : 读写,若文件已存在,内容不会清空 
rb :  仅读,二进制,待打开的文件必须存在 
wb : 仅写,二进制,若文件已存在,内容将先被清空 
ab:  仅写,二进制,若文件已存在,内容不会清空 
r+b: 读写,二进制,待打开的文件必须存在 
w+b: 读写,二进制,若文件已存在,内容将先被清空  
a+b: 读写,二进制,若文件已存在,内容不会清空

猜你喜欢

转载自www.cnblogs.com/tianmaodou/p/9023166.html