Well I've decided to rewrite into a simpler version like this:
#!/usr/bin/python
import sys
import tkFileDialog
filename = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")])
print filename
try:
file = open(filename)
except IOError, why:
print 'Unable to open file.\n', why
sys.exit(-1)
charCount = lineCount = wordCount = 0
for line in file.xreadlines():
lineCount += 1
wordCount += len(line.split())
charCount += len(line)
print "Number of lines:"
print lineCount,
print "Number of Words:"
print wordCount,
print "Number of characters:"
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