使用Python将句子写入CSV文件可以通过以下步骤实现:
import csv
sentences = ["Hello, world!", "This is a sentence.", "Python is awesome!"]
with open('sentences.csv', 'w', newline='') as file:
writer = csv.writer(file)
for sentence in sentences:
writer.writerow([sentence])
file.close()
完整的代码示例:
import csv
sentences = ["Hello, world!", "This is a sentence.", "Python is awesome!"]
with open('sentences.csv', 'w', newline='') as file:
writer = csv.writer(file)
for sentence in sentences:
writer.writerow([sentence])
file.close()
这样,句子将会被写入名为sentences.csv
的CSV文件中。每个句子将会被写入一行,并且被逗号分隔。
腾讯云相关产品和产品介绍链接地址:
请注意,以上仅为腾讯云的一些相关产品,其他云计算品牌商也提供类似的产品和服务。
领取专属 10元无门槛券
手把手带您无忧上云