String find and replace
hokiegal99
hokiegal99 at hotmail.com
Tue Aug 26 23:32:37 EDT 2003
Easy for you maybe ;)
That works great. I learn something each time I post to the list. With a
community like this, Python will be around forever!!! Thanks for the help.
Erik Max Francis wrote:
> hokiegal99 wrote:
>
>
>>I hate to answer my own post, but I think I understand what I'm doing
>>wrong. I'm finding and replacing 'this' with 'that' in the varible
>>named
>>mystr, not the actual files. So, how would I go about making the
>>change
>>to the actual files instead of a variable that contains their content?
>
>
> Easy:
>
> inputFile = file(filename, 'r')
> data = inputFile.read()
> inputFile.close()
> data = data.replace(this, that)
> outputFile = file(filename, 'w')
> outputFile.write(data)
> outputFile.close()
More information about the Python-list
mailing list