Why isn't my re.sub replacing the contents of my MS Word file?
wxjmfauth at gmail.com
wxjmfauth at gmail.com
Sat May 10 03:11:22 EDT 2014
Le samedi 10 mai 2014 06:22:00 UTC+2, Rustom Mody a écrit :
> 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
=========
That's a wise reommendation.
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.
LibreOffice could be a solution.
jmf
More information about the Python-list
mailing list