
8.5
By:
dvdjaco on
Feb 18th, 2012 | syntax:
Python | size: 0.44 KB | hits: 23 | expires: Never
# #!/usr/bin/python
#
# By dvdjaco
# Exercise 8.5
#
f = raw_input('Enter a file name: ')
try:
fhand = open(f)
count = 0
for line in fhand:
words = line.split()
# print 'Debug:', words
if len(words) == 0 or words[0] != 'From' : continue
print words[1]
count = count + 1
print "There were", count, "lines with 'From' as first word"
except IOError, err :
print "Error opening file", f
print "Error was:", err