Why isn't my re.sub replacing the contents of my MS Word file?

Tim Golden mail at timgolden.me.uk
Sat May 10 04:49:31 EDT 2014


On 10/05/2014 08:11, wxjmfauth at gmail.com wrote:
> Anyway, as Python may fail as soon as one uses an
> EM DASH or an EM DASH, I think it's not worth the
> effort to spend to much time with it.

Nope -- seems all right to me. (Hopefully helping the OP out as well as 
rebutting a rather foolish assertion).

<code>
#!python3.4
import win32com.client
import unicodedata

word = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
     doc1 = word.Documents.Add()
     doc1.Range().Text += "Hello \u2014 World"
     doc1.SaveAs(r"c:\temp\em_dash.docx")
     doc1.Close()

     doc2 = win32com.client.GetObject(r"c:\temp\em_dash.docx")
     for uchar in doc2.Range().Text.strip():
         print(unicodedata.name(uchar))

finally:
     word.Quit()

</code>

TJG



More information about the Python-list mailing list