Comment

Tam

I'm stuck with file reading, just thought the users here might be able to point out how to go about what I want to do.

The basic loop is

f = open("hello.txt")
try:
..for line in f:
....print line
finally:
..f.close()

as shown above.

However, in place of print line, I'm trying to search the current line for a particular string. I'm pretty new to Python, and I'm not sure how I do this. Can anyone here help me out with this? Thanks.

Replies

Peter Bengtsson

The short answer is::

if line.find('mystring') > -1:
....my_matched_function()

The long answer is:
http://docs.python.org/tut/node5.html#SECTION005120000000000000000

Anonymous

your link does not work along with everything else on this page.