1) I open a file
2) run re.findall()
returns a list as expected
3) then I run re.findall()
again looking for something else but it returns empty list.
But if I open the file again between 2 and 3, the second re.findall()
works perfectly.
I can't figure out what is going on, is re
closing the file? or is something else happening?
Thanks for any help you may have in advance!
Here's my code
def extract_names(filenames):
for f in filenames: #grabs one file at a time
file = open(f, 'r') #opens file
#find year <h3 align="center">Popularity in 1992</h3>
year = re.search(r'Popularity\sin\s\d{4}', file.read())
print(year)
file = open(f, 'r') #reopen file
#find <tr align="right"><td>1</td><td>Michael</td><td>Ashley</td>
rank_names = re.search(r'<td>\d*</td><td>\w*</td><td>\w*</td>', file.read())
print(rank_names)