python操作csv

追風箏的豬發表於2018-07-30
版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq_34173549/article/details/81285438
```def build_excel(self):
   workbook = xlwt.Workbook(encoding=`ascii`)
   # 建立表
   worksheet = workbook.add_sheet(`My Worksheet`)

   # 往表寫內容  行 ,列
   worksheet.write(1, 3, label=`Row 0, Column 0 Value`)
   workbook.save(`Excel_Workbook.xlsx`)
   

   csvFile = open("test42.cs v", `w`, newline=``)
   try:
      writer = csv.writer(csvFile)
      writer.writerow((`id`, `標題`, `釋出時間`,`視訊時長`, `播放次數`, `評論數`, `喜歡數`, `分享數`, `上傳使用者`, `下載地址` ))
      for i in range(10):
         writer.writerow((1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
   finally:
      csvFile.close()
return csvFile;


相關文章