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

MRAB python at mrabarnett.plus.com
Fri May 9 16:03:40 EDT 2014


On 2014-05-09 20:51, scottcabit 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?
>
>    Thanks!
>
> fn = 'z:\Documentation\Software'
> def processdoc(fn,outfile):
>      fStr = open(fn, 'rb').read()
>      re.sub(b'&#x2012','-',fStr)
>      re.sub(b'&#x2013','-',fStr)
>      re.sub(b'&#x2014','-',fStr)
>      re.sub(b'&#x2015','-',fStr)
>      re.sub(b'&#x2E3A','-',fStr)
>      re.sub(b'&#x2E3B','-',fStr)
>      re.sub(b'&#x002D','-',fStr)
>      re.sub(b'&#x00AD','-',fStr)
>
re.sub _returns_ its result (strings are immutable).




More information about the Python-list mailing list