Help

Thread Solved
Reply

Join Date: Mar 2006
Posts: 12
Reputation: JoshBebbington is an unknown quantity at this point 
Solved Threads: 0
JoshBebbington JoshBebbington is offline Offline
Newbie Poster

Help

 
0
  #1
Mar 25th, 2006
I have been looking over Vegaseat's Word Count program. I have two thoughts about what I want to configure it to do, but I'm not sure how to go about it.


Idea 1; This is most important. I want users to be able to put a text file in the same folder as the program, then the user can input 'Random.txt' or whatever the name is, and the program does its thing.

Idea 2; I want to make a graphical interface. I guess it would be a system of check input and doing it.




JB
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,837
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 861
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Help

 
0
  #2
Mar 25th, 2006
Which code snippet are you thinking of?

Wordcount of a text file (Python)
http://www.daniweb.com/code/snippet238.html
or
Word Frequency in a Text String (Python)
http://www.daniweb.com/code/snippet374.html
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 12
Reputation: JoshBebbington is an unknown quantity at this point 
Solved Threads: 0
JoshBebbington JoshBebbington is offline Offline
Newbie Poster

Re: Help

 
0
  #3
Mar 25th, 2006
I'm on about Wordcount of a text file (python)

Snippet 238.

Hope ya can help meh!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,837
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 861
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Help

 
0
  #4
Mar 25th, 2006
This would be the simplest way:
  1. filename = raw_input("Enter the name of the textfile (eg. test.txt): ")
Using a file dialog window to get a filename can be as simple as this with Tkinter:
  1. import tkFileDialog
  2.  
  3. filename = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")])
  4. print filename # for testing
Just incorporate this within the snippet code and you are set.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 12
Reputation: JoshBebbington is an unknown quantity at this point 
Solved Threads: 0
JoshBebbington JoshBebbington is offline Offline
Newbie Poster

Re: Help

 
0
  #5
Mar 26th, 2006
Well I've decided to rewrite into a simpler version like this:

  1. #!/usr/bin/python
  2. import sys
  3.  
  4. import tkFileDialog
  5.  
  6. filename = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")])
  7. print filename
  8.  
  9. try:
  10. file = open(filename)
  11. except IOError, why:
  12. print 'Unable to open file.\n', why
  13. sys.exit(-1)
  14.  
  15. charCount = lineCount = wordCount = 0
  16.  
  17. for line in file.xreadlines():
  18. lineCount += 1
  19. wordCount += len(line.split())
  20. charCount += len(line)
  21.  
  22. print "Number of lines:"
  23. print lineCount,
  24. print "Number of Words:"
  25. print wordCount,
  26. print "Number of characters:"
  27. print charCount

I have a few more questions:

1. I can't figure out for the life of me how to go about splitting the word count onto one line, character count on another etc. Does anyone know how? EDIT: Solved. Now it's perfect in that respect.

And 2. I want to try and write it so that it doesn't rely upon the python shell, but upon tkinter, like a window.

3. I want it to quit the tkinter window when done.

4. I want to package it into an executable.

If anyone can help it would be appreciated.

Edit: Added code tags vegaseat
Last edited by vegaseat; Mar 26th, 2006 at 9:51 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,837
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 861
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Help

 
0
  #6
Mar 26th, 2006
Graphics User Interface (GUI) programming isn't too difficult in Python, but you have to get used to the typical window widgets like buttons, frames, labels, entries, grids and so on.

My initial advice to you:
Get very familiar with the rudimentary Python syntax before you tackle GUI programming.

If I find some time, I will post a typical Tkinter template containing a button to load the file and a set of labels to show the result.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 12
Reputation: JoshBebbington is an unknown quantity at this point 
Solved Threads: 0
JoshBebbington JoshBebbington is offline Offline
Newbie Poster

Re: Help

 
0
  #7
Mar 28th, 2006
I am trying to put the wordcount program into a callable function, WordCount(), but when I indent everything correctly, it gives me an error and highlights the rest of the line that def WordCount() is on as a problem.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Help

 
0
  #8
Mar 29th, 2006
your putting ':' after the def WordCount() line arn't you, simple i know, but just checking...
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the Python Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC