editing text file
tim at remove_if_not_spam.digitig.cix.co.uk
Wed Jun 25 18:39:14 CEST 2003
On Wed, 25 Jun 2003 18:05:53 +0200, ataraxia2500
<messageboardfan1 at yahoo.com> wrote:
> is there a function that can search for specific words in a text file (kind
>of like grep) and change them?
>say in my text file there's a line such as:
>and my function would search the line [myvalue] and replace X by Y.
>thanx in advance
Use a for line in file.readlines() loop and the re module for your
matching. Though, to be honest, if that's all you want to do then
Python is probably an overkill; there's probably a port of sed for
your platform, whatever platform it is, and I reckon that would be the
appropriate level of tool.
More information about the Python-list