python - 使用 Python 写入 CSV 时如何将多个段落写入一个单元格
问题描述
我有 2 个变量正在使用 Python 写入 CSV。一个变量的数据,描述,是多个段落。如何防止新行写入新行?
from csv import writer
with open('test.csv', 'w', encoding='utf8', newline='') as file:
thewriter = writer(file)
header = ['Title', 'Description']
thewriter.writerow(header)
title = 'This is my title'
description = 'This is my long description, with 3 paragraphs.\r\nThis is the 2nd paragrapgh\r\nAnd here the 3rd paragrapgh'
info = [title, description]
print(info)
thewriter.writerow(info)
解决方案
上面的代码正在运行。感谢评论中的指导!
推荐阅读
- c# - 内部带有另一个 lambda 的 Lambda IfThenElse 表达式(用于 SetQueryFilter())
- python - 正则表达式在单词和标点符号之间添加 NOT
- lambda - 方法中与其参数引用之一相同的引用指的是参数正确吗?
- r - scala 将集合组合为一维集合
- r - R:计数组内的观察次数
- python - 如何在运行下一行代码之前更新 Tkinter 标签文本?
- php - 从 Yii2 中的相关表中订购一个表
- python - 基本 Python 循环
- php - 在脚本中多次调用 ini_set
- c++ - 关于 boost::function & 类型的返回对象的对象地址问题