For a simple record, read and write about both of these files:
Read/write CSV:
Import csv# read Data def getcsv (filename= "xxxxxxxx"): rows=[] with open (filename, ' RB ') as F: readers= Csv.reader (f,delimiter= ', ', quotechar= ' | ') Next (Readers,none) for row in readers: rows.append (Row) print rows# write Data def writecsv (filename= " Xxxxxxxxx "): with open (filename, ' WB ') as F: write =csv.writer (f) Write.writerow (" Element "," system ") data={ (' Selenium ', ' webdriver python '), (' Appnium ', ' Android Python '), (' Appnium ', ' iOS ') } Write.writerows (data) f.close () if __name__== ' __main__ ': writecsv () getcsv ()
For the use of with, you can refer to other people's explanations:
http://blog.csdn.net/suwei19870312/article/details/23258495/
About Readers=csv.reader (f,delimiter= ', ', quotechar= ' | ') The explanation of this sentence can be referred to the explanation of others:
http://blog.csdn.net/kaka_yidian/article/details/13000235
Read to a column:
1 defGetcsv (value1,value2,filename="xxxxxxxx"):2Rows=[]3with open (filename,'RB') as F:4Readers=csv.reader (f,delimiter=',', quotechar='|')5 Next (Readers,none)6 forRowinchReaders:7 rows.append (Row)8 returnrows (value1,value2)9 if __name__=='__main__':Ten PrintGetcsv (0,0)
Python read/write CSV