如何将第二行添加/合并到第一行?

2024-04-23 22:42:28 发布

您现在位置:Python中文网/ 问答频道 /正文

This is a real story,
and this is a good story

文本文件中有一个段落,有两行,当我打开它时

fileOpen=open(fileName,"r")
for word in fileOpen:
  file=word.split()
  print(file)

它印成这样:

["this", "is", "a", "real", "story"]
["and", "this", "a", "good", "story"]

我想把这个印成:

["this", "is", "a", "real", "story", "and", "this", "a", "good", "story"] 

这应该适用于整段,把整段读成一行。你知道吗


Tags: andisopenfilenamethisrealwordfile