Advertisement
dvdjaco

8.5

Feb 18th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. # #!/usr/bin/python
  2. #
  3. # By dvdjaco
  4. # Exercise 8.5
  5. #
  6.  
  7. f = raw_input('Enter a file name: ')
  8.  
  9. try:
  10.     fhand = open(f)
  11.     count = 0
  12.     for line in fhand:
  13.         words = line.split()
  14.         # print 'Debug:', words
  15.         if len(words) == 0 or words[0] != 'From' : continue
  16.         print words[1]
  17.         count = count + 1
  18.     print "There were", count, "lines with 'From' as first word"
  19.  
  20. except IOError, err :
  21.         print "Error opening file", f
  22.         print "Error was:", err
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement