![]() |
| ||
| RE: word count programming for python (wc) 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 |
| ||
| Re: word count programming for python (wc) Assuming the question does not want a count of unique words/characters this should do it: open the file for reading 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. |
| ||
| Re: word count programming for python (wc) Thanks bgeddy. I really do not have much clue as to what I am doing but I am very grateful for your response. Do I type the toggle as written? What am I expected to substitute in the toggle? Huglybits. |
| ||
| Re: word count programming for python (wc) Quote:
|
| ||
| Re: word count programming for python (wc) 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! |
| ||
| Re: word count programming for python (wc) You can use number = number + 1 or number += 1 |
| ||
| Re: word count programming for python (wc) 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. Good luck with python ! |
| ||
| Re: word count programming for python (wc) Thats right! I will try to understand this, it is not all complicated. Thanks for all your help! |
| ||
| Re: word count programming for python (wc) hi I tried to the program mentioned above ,but my problem is I can get them done as three separate programs instead of one.Can anyone help me out? |
| ||
| Re: word count programming for python (wc) I asked this question to someone back when I was coding my text editor(horrible project). THis is what that person gave me to use. def count_words(self):ITs a function that counts words. Hope this helps! |
| All times are GMT -4. The time now is 12:38 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC