1 #-*-coding:utf-8-*-2 " "3 Created on April 20, 20154 5 @author: Liuxue6 7 " "8 ImportCSV9 ImportSYSTen Reload (SYS) OneSys.setdefaultencoding ('Utf-8') A " " -Valuelist=[[]], double-decker list, each element represents a row of data - " " the - defCsvwrite (filename="", mode="", valuelist=[]): -csvfile=file (filename,mode) -Cstwriter=Csv.writer (csvfile) + forIinchRange (len (valueList)): -temp=[] +temp=Valuelist[i] A Cstwriter.writerow (temp) at csvfile.close () - - defCsvread (filename=""): -Csvfile=open (FileName,'R') -line = Csvfile.readline (). Strip ('\ r \ n')#If you have a title that you don't want to read, repeat this sentence -valuelist=[] in while(line!=""): -Temp=line.split (',') to valuelist.append (temp) +line = Csvfile.readline (). Strip ('\ r \ n') - csvfile.close () the returnvalueList * $ Panax Notoginseng defMain (): -valuelist=[["I'm","D"]] theCsvwrite ("Test.csv","WB", ValueList) +Value=csvread ("Test.csv") A forIinchRange (len (value)): thetemp=Value[i] + PrintTemp - forJinchRange (len (temp)): $ PrintTemp[j] $ - - if __name__=="__main__": the Main () - Wuyi " " the Output: - [' \xe6\x88\x91 ', ' d '] Wu I'm - D About " "
Python file----CSV