Reading a file

Terry Reedy tjreedy at
Sat Feb 14 18:45:44 CET 2009

zaheer.agadi at wrote:
> Hi
> How do i read  a file in Python and search a particular pattern
> like I have a file char.txt  which has
> Mango=sweet
> Sky=blue
> I want to get the strings sweet and blue,How to do this..?

for line in open('char.txt'):
   if line.find('sweet') != -1 or line.find('blue') != -1:

Read the section of the Lib Manual on string methods.

More information about the Python-list mailing list