Re: editing text file

Discussion in 'Python' started by Tim Rowe, Jun 25, 2003.

  1. Tim Rowe

    Tim Rowe Guest

    On Wed, 25 Jun 2003 18:05:53 +0200, ataraxia2500
    <> 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:
    >[myvalue]=X
    >
    >and my function would search the line [myvalue] and replace X by Y.
    >
    >any suggestions?
    >
    >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.
    Tim Rowe, Jun 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    574
  2. Shriphani
    Replies:
    2
    Views:
    268
    Larry Bates
    Oct 9, 2007
  3. barjunk

    Editing a text file

    barjunk, Apr 28, 2007, in forum: Ruby
    Replies:
    3
    Views:
    137
    Robert Klemme
    Apr 30, 2007
  4. Replies:
    6
    Views:
    125
    Joe Smith
    Jan 16, 2005
  5. deostroll
    Replies:
    1
    Views:
    146
    deostroll
    Jan 11, 2008
Loading...

Share This Page