这个小程序打开文件并读取文件。这两个for循环都可以正常工作。为什么如果我将它们结合起来,第二个for循环不会执行?
import os
import re
file = open(os.path.expanduser('~/Desktop/arbText.txt'))
for line in file:
line = line.rstrip()
if line.find('From: ') >= 0:
print(line)
print('\nLets try with re')
for line in file:
line = line.rstrip()
if re.search('From: ', line):
print(line)