lines = []
with open(file_name, 'r') as f:
for line in f:
lines.append(line)
with open(file_name, 'w+') as f:
flag = True
for line in lines:
f.write(line)
if line.startswith("example string") and flag:
f.write("what ever\n")
flag = False
输入文件
123456
example string<random>
asdfg
zxc
example string<random>
输出文件
123456
example string<random>
what ever
asdfg
zxc
example string<random>
从文件中读取行
输入文件
输出文件
相关问题 更多 >
编程相关推荐