【发布时间】:2020-04-21 09:50:21
【问题描述】:
我还在学习python,对函数readlines()有疑问以下是我脚本的一部分:
f = open("demofile.txt", "r")
text = "".join(f.readlines())
print(text)
demofile.txt 包含:
This is the first line
This is the second line
This is the third line
现在我想在其中添加一个单词,所以我得到:
This is the first line
This is the second line
This is the third line
Example
我想到了一些简单的方法:
f = open("demofile.txt", "r")
text = "".join(f.readlines())."Example"
print(text)
但这不起作用(当然)我用谷歌搜索并环顾四周,但实际上并没有很好的关键字来搜索这个问题。希望有人能指出我正确的方向。
【问题讨论】: