I have the following simple HTML
file.
<html data-noop=="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World</title>
</head>
<body>
SUMMARY1
hello world
</body>
</html>
I want to read this into a python
script and replace SUMMARY1 with the text "hi there" (say). I do the following in python
with open('test.html','r') as htmltemplatefile:
htmltemplate = htmltemplatefile.read().replace('\n','')
htmltemplate.replace('SUMMARY1','hi there')
print htmltemplate
The above code reads in the file into the variable htmltemplate
.
Next I call the replace()
function of the string object to replace the pattern SUMMARY1 with "hi there". But the output does not seem to search and replace SUMMARY1 with "hi there". Here is what I'm getting.
<html data-noop=="http://www.w3.org/1999/xhtml"><head><title>Hello World</title></head><body>SUMMARY1hello world</body></html>
Could someone point out what I'm doing wrong here?
htmltemplate = htmltemplate.replace('SUMMARY1','hi there')
and it worked. – broccoli Feb 24 '15 at 19:35