1. 写入多行(writerows
)
import csv with open('test.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(["6","6","6"])
test.csv 内容如下:
6 6 6
2. 写入一行(writerow
)
import csv with open('test.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerow(["6","6","6"])
test.csv 内容如下:
6,6,6
import csv with open('test.csv', newline='', encoding='utf-8') as f: reader = csv.reader(f) for row in reader: print(row) # ['6', '6', '6']