find string in file

Michael Wieher michael.wieher at gmail.com
Fri Mar 14 10:15:07 EDT 2008


2008/3/14, fminervino at gmail.com <fminervino at gmail.com>:
>
> Hi friends !!
>
> I'm neophite about python, my target is to create a programa that
> find  a specific string in text file.
> How can do it?
>
> Thanks
> fel
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If your only goal is to find a string in a file, just use grep
>grep -i 'string' filename

its a standard linux command =)

But if you must use python

data=file(filename,'r').read()
if string in data:
   return True
return False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080314/d7b23bf6/attachment-0001.html>


More information about the Python-list mailing list