simple text filter

boutrosp at hotmail.com boutrosp at hotmail.com
Wed Jun 11 16:36:52 EDT 2003


I need some help on a simple text filter. The problem I am having is
when the file comes to the end it stays in the while loop and does not
exit. I cannot figure this out. I would use a for loop with the
readlines() but my datasets can range from 5 to 80 MB of text data.
Here is the code I am using. Please help.

import sys, re

p1 = re.compile('ADT100')
p2 = re.compile('AUDIT')
p3 = re.compile('HARDWARE')
p4 = re.compile('PACKAGES')
p5 = re.compile('NODE')
p6 = re.compile('DROP')
p7 = re.compile('GRID')
p8 = re.compile('ATAP')

f=open('adt100_0489.rpt.txt', 'r')
junky = 1
done = False
while not done :
        junky = f.readline()
        if p1.search(junky) :
                continue
        elif p2.search(junky) :
                continue
        elif p3.search(junky) :
                continue
        elif p4.search(junky) :
                continue
        elif p5.search(junky) :
                continue
        elif p6.search(junky) :
                continue
        elif p7.search(junky) :
                continue
        elif p8.search(junky) :
                continue
        elif junky == None :
                done = True
        else :
                print junky

f.close()




More information about the Python-list mailing list