标签:
import csv with open(‘egg.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‘])
可以用excel打开csv文件
提示:使用python的csv生成excel所兼容的csv文件的话,主要就是创建writer时的参数时要有dialect=’excel’,就可以了。
import csv with open(‘egg.csv‘) as csvfile: reader = csv.DictReader(csvfile) for row in reader: print row
标签:
原文地址:http://www.cnblogs.com/whats/p/4877798.html