Reading a file
Terry Reedy
tjreedy at udel.edu
Sat Feb 14 12:45:44 EST 2009
zaheer.agadi at gmail.com 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:
print(line)
Read the section of the Lib Manual on string methods.
More information about the Python-list
mailing list