I am trying to make a word counter program incorporating easygui for file selection. I currently use Eclipse SDK with PyDev plugin (If there's any recommendations for a better Python environment).
Here is my code in its current state:
#This program is supposed to take a word file, and count the amount of lines and
#words. If the entered file is not a .txt, .doc, or .docx, then the program will
#ask for a different file.
from easygui import fileopenbox
filename = fileopenbox()
lines, words = 0, 0
#This method will count the amount of lines and words in a program and display
#it to the user
def word_count():
if filename.endswith('.docx'): #If the file extension is .docx
print("Your file has" + num_words + "words") #Print the amount of lines and words in the file.
elif filename.endswith('.doc'): #If the file extension is .doc
#<CODE WHICH COUNTS LINES AND WORDS>
print("Your file has", lines, "lines, and" ,"words") #Print the amount of lines and words in the file.
elif filename.endswith('.txt'): #If the file extension is .txt
#<CODE WHICH COUNTS LINES AND WORDS>
print("Your file has", lines, "lines, and" ,"words") #Print the amount of lines and words in the file.
elif filename.endswith('.py'): #If the file extension is .py
#<CODE WHICH COUNTS LINES AND WORDS>
print("Your file has", lines, "lines, and" ,"words") #Print the amount of lines and words in the file.
elif filename.endswith('.java'): #If the file extension is .java
#<CODE WHICH COUNTS LINES AND WORDS>
print("Your file has", lines, "lines, and" ,"words") #Print the amount of lines and words in the file.
else:
print("Are you trying to annoy me? How about giving me a TEXT or SOURCE CODE file, genius?")#Print an insulting error message.
As the code shows, I want the program to read the file extension, and if it matches any of those, run the word count code. However, my question is, what is that word count code? it seems like the use of fileopenbox() from easygui will make things even more complicated. any helps are appreciated thanks in advance