1. 程式人生 > >python3 writerow CSV檔案多一個空行

python3 writerow CSV檔案多一個空行

用 python3寫程式碼的時候發現, 使用下面的 wb開啟檔案,

import csv
with open('learn_csv.csv','w',encoding='utf-8',newline='') as f:
    writer = csv.writer(f)
    writer.writerow(['id','name','age'])
    writer.writerow(['1', 'stvev', '18'])
    writer.writerow(['2', 'cqx', '20'])
發現開啟CSV的時候多了一行空白行,

解決辦法:

with open('learn_csv.csv'
,'w',encoding='utf-8',newline='') as f:###,newline=''可以讓空一行的情況消失




解決辦法參考https://blog.csdn.net/pfm685757/article/details/47806469,侵請聯刪