Python reads CSV:
First you import the CSV library: importcsv
defLoadlist (filename,colmun1=2, colmun2=5): " "reads a coordinate file and returns a list. FileName is the file location + filename, for example: "./jiaodian.csv default Read columns 2nd through 4th"" "zblist=[] with open (filename,'R') as F:reader= Csv.reader (f)#each row is a list, made up of a large list by themcolumn = [ROW[COLMUN1:COLMUN2] forRowinchReader] forSanlistinchcolumn:nums= [Float (x) forXinchSanlist]#convert each element in each row to floatZblist.append (Nums)#Append into Zblist returnZblist
Python writes CSV:
With open ("./xxx.csv","W", newline="") as Data:csvwriter= Csv.writer (data, dialect= ("Excel")) forXinchlist1:csvwriter.writerow (x) Csvwriter.writerow ([]) Csvwriter.writerow (["A (0-0.5)","B (0.5-1)","C (1-1.5)","D (1.5-2)","E (2-5)","F (outside 5m)", "Total points (excl. f)"]) Csvwriter.writerow ([A,b,c,d,e,f,a+b+c+d+E]) csvwriter.writerow (['%.2f%%'% (a/h*100),'%.2f%%'% (b/h*100),'%.2f%%'% (c/h*100), '%.2f%%'% (d/h*100),'%.2f%%'% (e/h*100)])
Csvwriter = Csv.writer (data, dialect= ("Excel")) inside of Excel represents the generation of Excel-compatible CSV.
Each Csvwriter.writerow () is a separate line
Csvwriter.writerow ([]) can join a blank line
Python read/write CSV