Recently usedCSV file, So let's summarizeCSV Read write operation of file

1. Write inCSV file:




import csv     # Needimport csv File pack

out=open("aa.csv",'wb')         # Notice here if‘w’ Open in the form of, There will be a blank line in the middle of each data write, So we need to use it.‘wb’

csv_write=csv.write(out,dialect='excel')

                                              # Write the specific content below

ss=['a',3]

csv_write.writerow(ss)      # suchss The information is written intoaa.csv In the file, And it's in two columns

                                     # Here, if you need to write multiple lines, So it's OK to use cycle input

out.close()




2. readCSV file

import csv

out=open("aa.csv",'r')

read_csv=csv.reader(out,dialect='excel')

for line in read_csv:     # Cyclic outputcsv All data in

    print line

out.close()




It's still very simple, Ha-ha