I need to search through the file and look for lines that begin with "From". I need to parse the From line and print out the second word for each From line and then also count the number of From lines and print out a count at the end. I'm not sure what to do. Any help is appreciated.
Code:
import string
fname = raw_input("Enter a file name: ")
try:
infile = open(fname, "r")
except:
print "File not found:", fname
exit()
x = 0
for line in infile:
words = string.split(line)
print len(words), words
if ( words[0] == 'From' ) :
x = x + 1
print x, words[1]
elif (words[0] == ""):
x = x
continue
print "There were",x,"lines in the file with From as the first word"
Comment