Thank you so much. It works. But where can I find the APIs such as Dispatch vs gencache.EnsureDispatch? Now, I have another problem. Using the auto save, all auto-numbers before paragraphs are not read by the following code:
for word in doc.Content.Text.encode("cp1252", "replace").split(): print word count += 1 print "total word: " , count It works for the manual saved txt file. --- On Wed, 6/15/11, Tim Roberts <t...@probo.com> wrote: From: Tim Roberts <t...@probo.com> Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "Python-Win32 List" <python-win32@python.org> Date: Wednesday, June 15, 2011, 3:26 PM cool_go_blue wrote: > this is the first three lines of my code: > > app = win32com.client.Dispatch('Word.Application') > app.Documents.Open('D:\projects\Myself\HelloPython\src\Drugreservoir.doc') > app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > If you use this instead: app = win32com.client.gencache.EnsureDispatch('Word.Application') then the framework will build a Python wrapper for objects of that type, and that Python wrapper will create the constants. You MUST get in the habit of using the proper escape characters. The backslash has special meaning in Python strings. You have three choices: 1. Use a "raw" string: apps.Documents.Open(r'D:\projects\Myself\HelloPython\src\Drugreservoir.doc') 2. Double the backslashes: apps.Documents.Open('D:\\projects\\Myself\\HelloPython\\src\\Drugreservoir.doc') 3. Use forward slashes: apps.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir.doc') -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32