读取csv文件: def readCsv(): rows=[] with file(r'E:\py\py01\Data\system.csv','rb') as f: reads=csv.reader(f) for i in reads: rows.append(i) print rows return rows写入csv文件: def writer(): with file(r'E:\py\py01\Data\system.csv','wb') as f: writer=csv.writer(
1.写入excel,一开始不需要自己新建一个excel,会自动生成 attribute_proba是我写入的对象 import xlwt myexcel = xlwt.Workbook() sheet = myexcel.add_sheet('sheet') si=-1 sj=-1 for i in attribute_proba: si=si+1 for j in i: sj=sj+1 sheet.write(si,sj,str(j)) sj=-1 myexcel.save("attribut
转载解决写入csv中间隔一行空行问题 写入csv: with open(birth_weight_file,'w') as f: writer=csv.writer(f) writer.writerow(birth_header) writer.writerows(birth_data) f.close() 这种写法最终的结果就是生成的csv文件每两行中间都有一行空白行,解决办法就是写入后面加上newline='' 写法: with open(birth_weight_file,'w',newl