#!/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)

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐