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

Rustom Mody rustompmody at gmail.com
Sat May 10 00:22:00 EDT 2014


On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott... at gmail.com wrote:
> Hi,
> 
> 
> 
>  here is a snippet of code that opens a file (fn contains the path\name) and first tried to replace all endash, emdash etc characters with simple dash characters, before doing a search.
> 
>   But the replaces are not having any effect. Obviously a syntax problem....wwhat silly thing am I doing wrong?

If you are using MS-Word use that, not python.

Yeah it is possible to script MS with something like this
http://timgolden.me.uk/pywin32-docs/
[no experience myself!]
but its probably not worth the headache for such a simple job.

The VBA (or whatever is the modern equivalent) will be about as short and simple
as your attempted python and making it work will be far easier.

I way I used to do it with Windows-98 Word. 
Start a macro
Do a simple single search and replace by hand
Close the macro
Edit the macro (VBA version)
Replace the single search-n-replace with all the many you require



More information about the Python-list mailing list