[Tutor] searching in files

Kent Johnson kent_johnson at skillsoft.com
Wed Aug 11 16:55:54 CEST 2004

You can iterate over lines in a file without reading in the whole file at 
once, using
   for line in aFile:

 >>> f=open('index.html')
 >>> for line in f:
...   if '<h3>' in line:
...     print line
       <h3><i>Python Rocks!</i></h3>


       <h3>About me</h3>


At 07:46 AM 8/11/2004 -0700, Ali Polatel wrote:
>Yes I know the method readlines but the file is enorm large and it can 
>make the computer slow if I make the programme read all of it into a 
>Any other advices?
>Do you Yahoo!?
>Yahoo! Mail is new and improved - 
>it out!
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list