Home >Backend Development >Python Tutorial >Python导出数据到Excel可读取的CSV文件的方法

Python导出数据到Excel可读取的CSV文件的方法

WBOY
WBOYOriginal
2016-06-10 15:12:411173browse

本文实例讲述了Python导出数据到Excel可读取的CSV文件的方法。分享给大家供大家参考。具体实现方法如下:

import csv
with open('eggs.csv', 'wb') as csvfile:
  #spamwriter = csv.writer(csvfile, delimiter=' ',quotechar='|', 
  #quoting=csv.QUOTE_MINIMAL)
  spamwriter = csv.writer(csvfile, dialect='excel')
  spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
  spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn