how to tranlate a data from win32com in StringIO ? (unicode problem)

sebastien s.thuriez at quantaflow.com
Wed Dec 12 08:27:58 CET 2001


I have been looking to translate the output of

    caractere=mondoc.Words.Item(numero_caractere)

into a memory file object using stringIO.

Doing 

    file=StringIO.StringIO(first_word)

raises the exeption :

"...\win32com\client\__init__.py", line 348, in __getattr__ raise
attributeError, attr
AttributeError:__len__.

Do you have an idea of the problem ?
+ I was doing this in order to use the codec module to translate from
unicode to readeable format. Do you know off something more efficient?

Sebastien.



Here is the full code. The print mot really print the word that is
read from word provided that there is no èà caracters.

________________________________________________________
from win32com.client import constants, Dispatch
import StringIO
import codecs

word= Dispatch('Word.Application')
mondoc=word.Documents.Open(r"c:\testseb6.doc")
number_word=mondoc.Words.Count
for numero_word in range (1,int(number_word)+1):
    file=StringIO.StringIO()
    mot=mondoc.Words.Item(numero_word)
    print mot
    file.write(mot)
______________________________________________________



More information about the Python-list mailing list