Advertisement
Guest User

Untitled

a guest
May 17th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # P2PU - Python Programming 101 - Chapter 9 - Working with Files
  4. # Python for Informatics - Chapter 7 - Files
  5. # Exercise 7.3
  6.  
  7. print '\n# Exercise 7.3\n'
  8. fname =  raw_input('Enter a file name: ')
  9. if fname == 'na na boo boo':
  10.     print '*****************************************************'
  11.     print "***  NA NA BOO BOO TO YOU - You have been punk'd  ***"
  12.     print '*****************************************************'
  13.     exit()
  14. try:
  15.     ffile = open(fname)
  16. except:
  17.     print 'File', fname, 'cannot be opened!'
  18.     exit()
  19. count = 0
  20. for line in ffile:
  21.     if line.find('Subject:') != -1:
  22.       count += 1
  23. print 'There were %d subject lines in %s' % (count, fname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement