Python:CSV文件读写
#!/usr/bin/env python# coding:UTF-8"""@version: python3.x@author:曹新健@contact: 617349013@qq.com@software: PyCharm@file: CSV读写.py@time: 2018/9/12 16:32"""import csv,osdef c
·
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: CSV读写.py
@time: 2018/9/12 16:32
"""
import csv,os
def csvReader(path):
#abspath = os.path.join(os.getcwd(),path)
#allInfos = []
with open(path, "r") as csvfile:
allInfo = csv.reader(csvfile)
items = list(info for info in allInfo)
return items
def csvWriter(path,data):
#abspath = os.path.join(os.getcwd(), path)
with open(path, 'w', newline='') as csvFile: # 设置newline,否则两行之间会空一行
writer = csv.writer(csvFile)
m = len(data)
for i in range(m):
writer.writerow(data[i])
if __name__ == "__main__":
items = csvReader("111.CSV")
csvWriter("222.CSV",items)
更多推荐
已为社区贡献51条内容
所有评论(0)