读
with open(current_date+'.csv', encoding='utf-8') as f:
f_csv = csv.DictReader(f)
for row in f_csv:
print(row)
写
current_date = time.strftime('%Y-%m-%d', time.localtime(time.time()))
current_time = time.strftime('%H:%M:%S', time.localtime(time.time()))
f = open(current_date+'.csv', 'a', encoding='utf-8', newline='')
csv_writer = csv.writer(f)
csv_writer.writerow([current_time, str(bo_total) + '\t', str(so_total) + '\t'])
f.close()
避免生成数据之间有空行
f = open(current_date+'.csv', 'a', encoding='utf-8', newline='')
避免生成数据记录成科学计数法
在代码端将这个字段分离出来,改变成字符串,并加上" \t" 就可以解决这个问题
csv_writer.writerow([current_time, str(bo_total) + '\t', str(so_total) + '\t'])
网友评论