'''words.py -- a function for retrieving words from an input file Jeff Ondich, 9/18/07 The getword() function defined in this module returns the next word available from standard input. A "word" is defined to be a maximal contiguous block of letters and apostrophes. For example, the first word in this file is "words", not "w" or "wo" or "wor", etc. Note that this definition of word will allow some pretty weird things to be considered words. For example, "abc'x'y'z''" or just a single apostrophe will be considered legitimate words. On the other hand, disallowing apostrophes in words would turn "don't" into a pair of words: "don" and "t". ''' import sys def getword(theFile): word = '' ch = theFile.read(1) while ch: if ch.isalpha() or ch == "'": word += ch elif word: break ch = theFile.read(1) return word