| | |
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:
Solved Threads: 0
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.
Python Syntax (Toggle Plain Text)
#The number of lines, and the number of words. import string def main(): data = raw_input("Enter the path and name of your ") infile = file(data, 'r') data_file = infile.read() number_of_characters = len(data_file) print "The number of characters in your text is", number_of_characters list_of_words = string.split(data_file) number_of_words = len(list_of_words) print "The number of words in your text is", number_of_words infile.close() secondfile = file(data, 'r') line_of_text = secondfile.readlines() print line_of_text number_of_lines = len(lines_of_text) print "The number of lines in your text is" , number_of_lines infile.close() main()
Last edited by vegaseat; Mar 2nd, 2006 at 2:35 am.
![]() |
Similar Threads
- Word Count Issues (Python)
- word count (C++)
- Word count help. (C++)
- I Need Help Writing A Word Count Program In My Python (Python)
- word count in borland c++ ?? (C++)
- word count (Java)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the Python Forum
- Previous Thread: I Need Help Writing A Word Count Program In My Python
- Next Thread: Here Is Another Way That I Wrote Word Count Did I Write It Right
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change command convert count csv cturtle cursor def dictionary digital dynamic dynamically enter event examples external file float format frange function google gui hints homework i/o iframe import info input jaunty java keyboard lapse line linux list lists loop microphone mouse multiple newb number numbers obexftp output parameters parsing path port prime programming projects py py2exe pygame pygtk pyopengl python random recursion return scrolledtext signal skinning sprite stderr string strings subprocess table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 variable voip web-scrape whileloop windows wxpython





