[英]I'm trying to record date and time from local into .csv file but it displays `,` in between every character
我正在嘗試每秒將日期和時間記錄到 .csv 文件中(用於將來制作實時圖表)。 根據我的代碼,將顯示以下結果,
在每一個字符之間。 有沒有辦法擺脫它們?
預先感謝您提供任何解決方案。
這是我的代碼
import csv
import time
def processing_loop(csvfile):
csv_writer = csv.writer(csvfile)
while True:
localtime = time.localtime()
result = time.strftime("%c", localtime)
csv_writer.writerow(result)
csvfile.flush()
time.sleep(1)
with open('results.csv', 'w') as csvfile:
processing_loop(csvfile)
結果顯示在我的 .csv 文件中。
M,o,n, ,J,u,l, ,1,9, ,1,5,:,2,8,:,4,0, ,2,0,2,1
writerow 期望它可以迭代的東西......它可以迭代一個字符串,使每個字母成為一列
只要確保你給它一個清單
csv_writer.writerow([result])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.