import string # If you don't then write down the whole list of strings a-zA-Z count = 0 try: # Counting user input is too much easy fname = open(raw_input("Enter File name : ")).read() # Warning, len(fname) cannot be used. # Because it also counts all those spaces. except IOError: print"File not found!" else: for i in fname: if i in string.ascii_letters: # if i in a-zA-Z count +=1 print"Word Count is : %s" % count