I'm working on the exercise in the book Python for Informatics which asks me to write a program to simulate the operation of the grep command on UNIX. However, my code doesn't work. Here I simplified my code and only intend to calculate how many lines start with the word 'Find'. I'm quite confused and wish you could cast light on it.
from urllib.request import urlopen
import re
fhand = urlopen('http://www.py4inf.com/code/mbox-short.txt')
sumFind = 0
for line in fhand:
line = str(line) #convert from byte to string for re operation
if re.search('^From',line) is not None:
sumFind+=1
print(f'There are {sumFind} lines that match.')
The output of the script is
There are 0 lines that match.
And here is the link of the input text: text
Thanks a lot for your time.