[Tutor] best search/replace method?
washakie at gmail.com
Wed Apr 25 23:20:11 CEST 2007
I thought it would be something like that, but that doesn't work..
perhaps because 'ImagePathReplaceMe' isn't separate from the rest of
the path??? Maybe replace has some options... I'll look into that.
On 4/25/07, Rikard Bosnjakovic <rikard.bosnjakovic at gmail.com> wrote:
> On 4/25/07, John Washakie <washakie at gmail.com> wrote:
> > cat raw.html |
> > sed 's/ImagePathReplaceMe/NewPathToImage/g' |
> > sed 's/TitleReplaceMe/NewTitle/g' > new.html
> One line's sufficient:
> sed -e 's/ImagePathReplaceMe/NewPathToImage/g;s/TitleReplaceMe/NewTitle/g'
> raw.html > new.html
> > However, this is going to be part of an Plone product so I want to use
> > Python. What is the best method to accomplish this?
> d = open("raw.html").read()
> d.replace("ImagePathReplaceMe", "NewPathToImage")
> d.replace("TitleReplaceMe", "TitleReplaceMe")
> x = open("new.html", "w")
> - Rikard - http://bos.hack.org/cv/
More information about the Tutor