如何用Python读写CSV文件?我有一份文件example.csv有内容1,"A towel,",1.042," it says, ",2.01337,is about the most ,-10,massively useful thing ,123-2,an interstellar hitchhiker can have.,3我怎么看这个?example.csv和Python?同样,如果我有data = [(1, "A towel,", 1.0),
(42, " it says, ", 2.0),
(1337, "is about the most ", -1),
(0, "massively useful thing ", 123),
(-2, "an interstellar hitchhiker can have.", 3)]我怎么写data到带有Python的CSV文件中?
3 回答

桃花长相依
TA贡献1860条经验 获得超8个赞
编写CSV文件
import csvwith open('eggs.csv', 'wb') as csvfile: spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) spamwriter.writerow(['Spam'] * 5 + ['Baked Beans']) spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

潇潇雨雨
TA贡献1833条经验 获得超4个赞
import csvwith open(fileLocation+'example.csv',newline='') as File: #the csv file is stored in a File object reader=csv.reader(File) #csv.reader is used to read a file for row in reader: print(row)
添加回答
举报
0/150
提交
取消