1.读取CSV文件
python
import csv
path = "123.csv"
with open(path) as f: # 打开csv文件
csvReader = csv.reader(f) # 读文件建立Reader对象
listReader = list(csvReader) # 将数据转换成列表
print(listReader)
2.写入CSV文件
python
import csv
path = "123.csv"
with open(path, 'w') as f: # 打开csv文件
csvWriter = csv.writer(f) # 读文件建立Writer对象
# 按行写入数据(重写)
csvWriter.writerow("['a', 'b', 'c']")