I would like some advice as to how to write my wc program. Program should accept a file name as input and then print three numbers showing the count of lines, words and characters in the file. Chapter 4 question 15 of zelles introduction to python
Assuming the question does not want a count of unique words/characters this should do it:
open the file for reading
number of words,characters, lines = 0
while a line can be read from the file read a line into a string
number of lines + = 1
number of characters + = length of string
number of words + = length of string split into a list of words
print out number of words, lines, characters
Obviously this is not python but pseudo code that will very easily translate into python - I'll leave that to you. Look into string functions for splitting strings into a list of words (hint). The length of this list will give you the number of words. The length of a string is the number of characters and the number of line reads is the number of lines.
Do you want the program to ask the user to key in a file name, or do you want to provide it as an argument when the program is called, or do you want to use a GUI that allows the user to browse the file system and choose a file?
I believe I want to use a GUI that allows the user to browse the file system and choose a file or to ask the user to key in a file name. I got the file which is saved in a .txt file. bgeddy used some + signs in his toggle please tell me what to do. Thanks woooee!
Sorry for not getting back sooner but it seems other kind folks in the forum have answered already.
It's hard to gauge someones level of experience when answering a question but I only outlined the program's logic broadly.
I recommend studying a beginners tutorial on python and playing around in the interpreter, following examples etc to get a feel for things.
Personally, if you are just starting out with programming in general, I wouldn't recommend developing gui front ends just yet. Perhaps just "raw_input() to read input from the user and "print " to output it.
Please don't take offence if I underestimate your level of experience and don't think I'm being deliberately vague in offering a solution. If I were to simply give you python code for a complete working program I don't think you'd learn as much as doing it for yourself. If this is a homework assignment, simply copying an offered solution verbatim will give a false impression of your proficiency.