一,python使用csv模块读取CSV文件,与读取普通文件是一样的,比较简单。
代码:
二,python通过csv模块写入Excel格式的CSV文件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# write csv file
import csv
with open('egg2.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile,dialect='excel')
spamwriter.writerow(['a', '1', '1', '2', '2'])
spamwriter.writerow(['b', '3', '3', '6', '4'])
spamwriter.writerow(['c', '7', '7', '10', '4'])
spamwriter.writerow(['d', '11','11','11', '1'])
spamwriter.writerow(['e', '12','12','14', '3'])