在下面的代码中,我想打印“first”之间的行,并在那些搜索“new.txt”行的行上..当我运行时出现错误:
if "first" in lines[i+n]:
IndexError: list index out of range
我的代码:
def find_path(self):
f = open("/output",'w')
for line in self.logs:
f.write(line)
f = open('/output','rb')
lines = f.readlines()
for i,line in enumerate(lines):
if "first" in line:
pattern = line
for n in range(1,len(lines)):
if "first" in lines[i+n]:
break
else:
if "new.txt" in line:
print line
print lines[i+n]
f.close()