importwin32com.clientaswin32fromtimeimportsleepRANGE=range(3,8)defword():word=win32.gencache.EnsureDispatch('Word.Application')doc=word.Documents.Add()word.Visible=Truesleep(1)rng=doc.Range(0,0)rng.InsertAfter('Hacking Word with Pythonrnrn')sleep(1)foriinRANGE:rng.InsertAfter('Line %drn'%i)sleep(1)rng.InsertAfter("rnPython rules!rn")doc.Close(False)word.Application.Quit()if__name__=='__main__':word()