Python文件之----CSV

 # -*- coding:utf-8 -*-
'''
Created on 2015年4月20日 @author: liuxue '''
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
'''
valueList=[[]],双层列表,每一个元素代表一行数据
''' def csvWrite(fileName="",mode="",valueList=[]):
csvFile=file(fileName,mode)
cstWriter=csv.writer(csvFile)
for i in range(len(valueList)):
temp=[]
temp=valueList[i]
cstWriter.writerow(temp)
csvFile.close() def csvRead(fileName=""):
csvFile=open(fileName,'r')
line = csvFile.readline().strip('\r\n')#如果有标题不想读取,可以重复这句
valueList=[]
while(line!=""):
temp=line.split(',')
valueList.append(temp)
line = csvFile.readline().strip('\r\n')
csvFile.close()
return valueList def main():
valueList=[["我","d"]]
csvWrite("test.csv","wb",valueList)
value=csvRead("test.csv")
for i in range(len(value)):
temp=value[i]
print temp
for j in range(len(temp)):
print temp[j] if __name__=="__main__":
main() '''
输出:
['\xe6\x88\x91', 'd']

d
'''
上一篇:Django views 中 View decorators


下一篇:201521123105 第9周Java学习总结