csv_name = "source/Test_source_data/WD{0}mm_d{1}mm_rpm{2}.csv".format(wd,Diameter,rpm) with open(csv_name, 'w', newline='') as csvfile: writer = csv.writer(csvfile,quoting=csv.QUOTE_ALL) writer.writerow(['ts', 'dx','dy','motion','iqc','shutter','frame_avg']) while self.is_running: com_input = ser.readall() if com_input: # 如果读取结果非空,则输出 com_input = str(com_input, 'utf-8') com_input =com_input.replace("\r"," ").replace(","," ") data_list = com_input.split(",") print(data_list) writer.writerow(data_list) 串口数据中有\n 但是无法换行
时间: 2024-01-14 11:02:31 浏览: 75
song_data.csv
你可以使用 `replace` 函数将 `\n` 替换为空格或其他字符,例如:
```
com_input = com_input.replace("\r", " ").replace("\n", " ").replace(",", " ")
```
这样可以将 `\n` 替换为空格,避免写入 csv 文件时出现换行的问题。
阅读全文