Python CSV写入操作

#!/user/bin/env python3
# -*- coding: utf-8 -*-

import csv
with open("./test.csv",'w',encoding='gbk',newline='') as f:
    csv_writer=csv.writer(f)
    csv_writer.writerow(['shiyu41','18','男'])
    csv_writer.writerow(['x','18','女'])
    csv_writer.writerow(['l','18','男'])
    csv_writer.writerows([[0, 1, 2], [3, 4, 5], [6, 7, 8]])  # 写入多行writerows
    f.close()


你可能感兴趣的:(Python文件操作)