String find and replace

John Roth newsgroups at
Wed Aug 27 03:54:19 CEST 2003

"hokiegal99" <hokiegal99 at> wrote in message
news:3F4C0CC4.20400 at
> 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.

John Roth

More information about the Python-list mailing list