写入csv

2021-05-24  本文已影响0人  还是那个没头脑
import csv
import os.path

filename = 'notice.csv'
file_exists = os.path.isfile(filename)

def writeCSV(appName,title,description,orignUrl):

    rows = [appName, title, description, orignUrl]

    with open(filename, 'a+', encoding='utf-8-sig')as csvfile:
        headers = ['appName', 'title', 'description', 'orignUrl']
        writer = csv.writer(csvfile)

        if not file_exists:
            writer.writerow(headers)

        writer.writerow(rows)

writeCSV("人民日报", '起风了','大风起兮云飞扬','https://wap.peopleapp.com/article/rmh20732791/rmh20732791')
上一篇下一篇

猜你喜欢

热点阅读