python csv模块使用
来源:互联网 发布:知乎 高中生 编辑:程序博客网 时间:2024/06/06 19:27
在windows操作系统中出现空行的情况
import csv
header = [‘row1’, ‘row2’, ‘row3’]
data = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
with open(‘testCSV.csv’, ‘w’, newline=”) as f:
writer = csv.writer(f)
writer.writerow(header)
writer.writerows(data)import csv
with open(‘testCSV.csv’, ‘r’, newline=’\n’) as f:
reader = csv.reader(f)
for row in reader:
print(row)
在操作文件时添加newline参数就可以解决window操作系统空行问题!
其参数可以为:None, ”, \n, \r, \r\n;
说明:newline参数只有在pyhon3版本进行了添加!
参数说明可参阅此博客:http://www.cnblogs.com/meitian/p/4625011.html
阅读全文
0 0
- python csv模块使用
- python csv模块使用
- python使用csv模块读写csv文件
- 【Python】 csv模块的使用
- python csv模块的使用
- python CSV模块使用笔记
- python csv模块使用实例
- 【Python】 csv模块的使用
- Python csv模块的使用
- Python csv模块的使用
- 【Python】 csv模块的使用
- 【Python】 csv模块的使用
- 【Python】 csv模块的使用
- Python csv模块的使用
- Python-使用CSV模块进行文件处理
- Python csv 模块
- Python的CSV模块
- Python csv模块
- [python] 在ubuntu中, 如何运行指定位置的py程序
- oracle
- Ohana Cleans Up
- css背景
- javaweb文件上传的九大问题
- python csv模块使用
- hdu1839 spfa+二分查找
- Spark编程之基本的RDD算子之zip,zipPartitions,zipWithIndex,zipWithUniqueId
- 深度优先搜索
- java中instanceof和isInstance
- C++_Seqlist/Linklist
- POJ3259 解题报告
- 2017ICPCECIC
- 同步、异步、阻塞、非阻塞的理解