[2.5.1] Str.Replace() doesn't work?

Gilles Ganault nospam at nospam.com
Fri Dec 26 15:16:49 CET 2008


Hello

	I need to parse an HTML file where records aren't homogenous, so I
figured I could run a first loop to add an unused character at the
beginning of each record, and then run a second loop to actually parse
each record.

I can't figure out why the script is not returning anything in the
"for m in matches" block:

=========
f = open("input.txt", "r") 
response = f.read()
f.close()

#Pass 1: Add some character to separate records
#response.replace('<li class="N2"','µ<li class="N2"')
reponse = response.replace('<li class="N2"','µ<li class="N2"')
p = re.compile('µ')
index=1
matches = p.finditer(response)
#Python doesn't display anything :-/
for m in matches:
	print "Found %s" % str(index)
	index = index + 1
=========

Any idea what I could be doing wrong?

Thank you for any tip.



More information about the Python-list mailing list