String find and replace
newsgroups at jhrothjr.com
Wed Aug 27 03:54:19 CEST 2003
"hokiegal99" <hokiegal99 at hotmail.com> wrote in message
news:3F4C0CC4.20400 at hotmail.com...
> John Roth wrote:
> > Are you trying to rename the file? Look under os - Files and Directories
> > for the rename() function. It's 6.1.4 in the 2.2.3 docs.
> > John Roth
> No, I'm trying to find 'this' in files and replace it with 'that'
> recursively through a directory. It works, but it doesn't actually
> commit the change to the files, it finds 'this' and reports that it
> replaced it with 'that', but when I run the scipt again it reports the
> same files that it just fixed.
Oh. You need to open it again for write and write the
changed string back out. The string doesn't have any
persistant connection to the file.
More information about the Python-list