首页 > 其他 > 详细

CSV文件的基本操作

时间:2017-11-24 19:35:53      阅读:192      评论:0      收藏:0      [点我收藏+]
# hanbb
# come on!!!
import csv

# 文件的整体读取
examplefile= open(E:\\download\es.txt)    # 打开文件
examplereader = csv.reader(examplefile)     # 读取文件  注意不能直接访问文件名字,必须先打开
examplerdata = list(examplereader)          # 将返回为内容变成列表 操作

# 文件的逐行读取
openfile = open(E:\\download\es.txt)      # 先打开
readfile = csv.reader(openfile)             # 读取
#for row in readfile:                        # 循环读取
    #print("row # " + str(readfile.line_num)+ ‘ ‘ +str(row))

# 文件的写入
file = open(E:\\download\writer.csv,w,newline=‘‘)  # 打开的文件名称,写入模式,不写newline=‘‘会出现行间距变大
writerfile = csv.writer(file)                          # 写入命令
writerfile.writerow([name,address,city,state]) # 写入内容
writerfile.writerow([hbb,hangzhou,hangzhou,china])
file.close()                                           # 关闭文件

 

CSV文件的基本操作

原文:http://www.cnblogs.com/hanbb/p/7891854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!