search for a string?

Ken Seehof 12klat at sightreader.com
Thu Jun 1 19:17:40 EDT 2000


Shengquan Liang wrote:

> how do i search for a string in a document
>
> and inseart content of another file before
> that string?

>>> import string
>>> f = open("todo.txt")
>>> s = f.read()
>>> print s
Today's Menu:
  spam and jelly sandwitch
  eggs
  spamburger

>>> n = string.find(s, 'eggs')
>>> s = s[:n] + 'spam and ' + s[n:]
>>> print s
Today's Menu:
  spam and jelly sandwitch
  spam and eggs
  spamburger






More information about the Python-list mailing list