printing from Word using win32com

Frederick H. Bartlett fbartlet at wiley.com
Wed Jan 2 10:26:58 EST 2002


Mark Hammond <mhammond at skippinet.com.au> wrote in message news:<3C32AC2E.3030704 at skippinet.com.au>...

Mark,

Thanks for the response. But item.encode('latin-1') gives me
  AttributeError: <unknown>.encode
so I must not have a COM string. But if it's not a COM string, what
could it be? Python's print will work so long as the object contains
only 7-bit characters.

The items I'm trying to print are Word paragraphs, as in
   something = myWord.ActiveDocument.Paragraphs
   for item in something:

Happy New Year!
Fred

> Oops - I missed the original:
> 
> >>       try:
> >>           print str(item).encode('latin-1')
> >>       except UnicodeError:
> >>           print "XXX There was a Unicode Error."
> 
> 
> Just:
>    print item.encode('latin-1')
> 
> should work assuming item is always a COM string (ie, a Unicode object). 
>   Note that using "mbcs" may be a better choice depending on your user base.



More information about the Python-list mailing list