像這樣。
這是因為導入的時候,是這樣寫的:
with open('book_statics.csv', 'w+') as csvfile: writer = csv.writer(csvfile) for i in ans: writer.writerow(i)
只要改成wb+,也就是寫二進制文件,就好了嗎?
with open('book_statics.csv', 'wb+') as csvfile: writer = csv.writer(csvfile) for i in ans: writer.writerow(i)
並沒有!!!
報錯:TypeError: a bytes-like object is required, not 'str'
查閱了官方文檔,改成如下即可
with open('book_statics.csv', 'w+', newline='') as csvfile: writer = csv.writer(csvfile) for i in ans: writer.writerow(i)
成功解決。