############################################################################# # # words.py # # Jeff Ondich, 1/10/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'''xyz'''" 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(): word = '' ch = sys.stdin.read(1) while ch: if ch.isalpha() or ch == "'": word += ch elif word: break ch = sys.stdin.read(1) return word