python 写入CSV

#coding:utf-8
import time
import json
import csv

class MadeCsv:

    def __init__(self, filename, title, data):
        self.filename = filename
        self.title = title
        self.data = data
        self.filepath = '/root/'

    def docsv(self):

        csvfile = file(self.filepath+'test.csv', 'wb')
        csvfile.write(u'\ufeff'.encode('utf8'))
        writer = csv.writer(csvfile)
        writer.writerow(self.title) #标题
        writer.writerows(self.data) #内容
        csvfile.close()


if __name__ == '__main__':

    c = MadeCsv(1,2)

    c.test()

 

你可能感兴趣的:(python)