matching one time through a loop

Corey G. ctgaff at attbi.com
Wed May 29 21:13:37 EDT 2002


I have a script that parses some email from a Maildir directory 
and I am looking for the number 550.  I want to stop searching once 
the first occurrence is found in order to save time and be efficient.  
This sort of thing can be done in Perl using the "last" statement.  
I achieved my goal by using a counter but it seems terribly inefficient.  
Any ideas?


#!/usr/local/bin/python

import re
import glob

tglob=glob.glob('/home/pmail/Maildir/test3/*')

for i in tglob:
        count=0
        file=open(i, 'r')
        contents = file.readlines()

        for sepem in contents:
                tm=re.compile(" 550 ")
                match=tm.search(sepem)
                if match:
                        if count == 0:
                                count+=1
                                print match.group(), i

-- 
Best Regards,
Corey





More information about the Python-list mailing list