Can you please help me write this word count program in another way

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2006
Posts: 43
Reputation: butterflyTee is an unknown quantity at this point 
Solved Threads: 0
butterflyTee butterflyTee is offline Offline
Light Poster

Can you please help me write this word count program in another way

 
0
  #1
Feb 27th, 2006
Word Count. A Common Utility On Unix/linux Systems Is A Small Program Called "wc." This Program Analyzes A File To Determine The Number Of Lines, Words, And Characters Contained Therein. Write A Version Of Wc. The Program Should Accept A File Name As Input And Than Print Three Numbers Showing The Count Of Lines, Words, And Characters In The File. I use Gettysburg address.

  1. #The number of lines, and the number of words.
  2.  
  3.  
  4. import string
  5.  
  6.  
  7. def main():
  8. data = raw_input("Enter the path and name of your ")
  9. infile = file(data, 'r')
  10. data_file = infile.read()
  11. number_of_characters = len(data_file)
  12. print "The number of characters in your text is", number_of_characters
  13.  
  14. list_of_words = string.split(data_file)
  15. number_of_words = len(list_of_words)
  16. print "The number of words in your text is", number_of_words
  17. infile.close()
  18.  
  19. secondfile = file(data, 'r')
  20. line_of_text = secondfile.readlines()
  21. print line_of_text
  22. number_of_lines = len(lines_of_text)
  23. print "The number of lines in your text is" , number_of_lines
  24.  
  25. infile.close()
  26.  
  27. main()
Last edited by vegaseat; Mar 2nd, 2006 at 2:35 am.
Attached Files
File Type: doc gettysburg address.doc (20.0 KB, 4 views)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC