# speling.py # a happy little python module that provides spellchecking import xreadlines,re global mydicta global wordpattern mydicta = { } wordpattern = re.compile('^[\\w\-\'\"]*$') def check_word(word): """Takes a word (string) and looks it up in the dictionary object. Returns a list, containing the same word if the word is spelled correctly, or else a list of any possible corrections out of the dictionary object. This lookup is case-sensitive.""" try: if mydicta[word] == 1: return [ word ] else: return [ ] except StandardError: return [ ] def import_entries(filename): """Takes a file name and imports words separated by \\n from a text file. Returns 0 if successful. Returns error if failure.""" try: dictafile = open(filename) except StandardError: return StandardError for line in xreadlines.xreadlines(dictafile): word = line.replace('\n','') if wordpattern.search(word): mydicta[word] = 1 else: word = "Import file is not of appropriate word\nword\n format, " +\ "but instead: " + word return word dictafile.close() return 0 # the rest of these funtions are not implemented currently. def export_entries(): """Takes a file name and exports dictionary entries into a text file. Returns 0 if successful.""" pass def load_dictionary(): """Takes a file path and loads a dictionary file into memory, returning the dictionary object. This function is called whenever a dictionary object is created.""" pass def save_dictionary(): """Saves a dictionary object to disk, takes an optional file path to save it in a place different than its original location.""" pass def add_entry(): """Takes a word (string) and adds it to the dictionary object.""" pass def remove_entry(): """Takes a word (string) and removes it from the dictionary object. Returns true if it was successful.""" pass