如果我有这样的文本文件:
[001]This is line 1.
[002][too long]This is line 2 but it's Tooooo
oooo long!
[003]This is line 3.
我写了一个'for line in fileA'来读取这个文件,比如:
for line in fileA:
...
现在我需要在 line.find("[too long]")>=0 时合并当前行和下一行。我应该怎么做?
PS:我写道:
for line in fileA:
if line.find("[too long]")>=0:
loc = fileA.tell()
fileB = open("file.txt") #open this file again
fileB.seek(loc)
line += fileB.readline().strip()
但它没有用。为什么?