Problem Converting Word to UTF8 Text File
gagsl-py2 at yahoo.com.ar
Mon Oct 22 05:39:20 CEST 2007
En Sun, 21 Oct 2007 15:32:57 -0300, <patrick.waldo at gmail.com> escribi�:
> However, I still cannot read the unicode from the Word file. If take
> out the first for-statement, I get a bunch of garbled text, which
> isn't helpful. I would save them all manually, but I want to figure
> out how to do it in Python, since I'm just beginning.
> My intuition says the problem is with
> because it converts fine to a text file, just not a utf-8 text file.
> How can I modify this or is there another way to code this type of
> file conversion from *.doc to *.txt with unicode characters?
Ah! I thought you were getting the right file format.
I can't test it now, but this KB document
suggests you should use wdFormatUnicodeText when saving the document.
What the MS docs call "unicode" when dealing with files, is in general
In this case, if you want to convert to utf8, the sequence would be:
f = open(original_filename, "rb")
udata = f.read().decode("utf16")
f = open(new_filename, "wb")
More information about the Python-list