python-3.x - 如果以 CSV 格式存储,如何将 \n 作为文本的一部分读取
问题描述
我已经设置delimiter="|"
,newline="\n"
但是当我阅读文本时,文本中的 \n 并没有给我一个新的打印行。例如:
"Good Morning \nHow are you?"|"Its been a while since we met."
当我将对象作为列表的元素时csv.reader
with open ('file.csv', 'r', newline="\n") as f:
r = csv.reader(f, delimiter='|')
List = []
for lines in r:
List.append(lines)
List
看起来像这样
["Good Morning \nHow are you?","Its been a while since we met."]
如果我运行代码
for i in list:
print i
元素的预期输出将是
Good Morning
How are you?
Its been a while since we met.
但我最终得到的是
Good Morning \nHow are you?
Its been a while since we met.
而如果我直接分配List=["Good Morning \nHow are you?","Its been a while since we met."]
,我不会遇到这个问题。有什么解决方法吗?
我需要在文本中同时使用 CSV 和 \n。
解决方案
推荐阅读
- scala - 用空值替换空字符串
- postgresql - Google Cloud SQL - Postgresql 存储不断增长
- python - 从父类访问子类中定义的属性
- javascript - 当我单击班级中的按钮时,如何获得提醒?
- automated-tests - 使用 puppeteer 进行多用户 e2e 测试
- javascript - 如何从angular 8中的javascript函数触发打字稿功能
- sql-server - 在什么存储过程中从 ssrs 接收多值参数?
- tensorflow - TF/Keras:ModelCheckpoint "period" 和 "save_best_only"
- regression - 负二项式回归 SPSS - 数量与距离
- reactjs - 检查反应中唯一孩子的类型