matching one time through a loop

Corey G. ctgaff at attbi.com
Wed May 29 22:07:54 EDT 2002


Seems to work with break now.  Much thanks.

Corey

On Thu, May 30, 2002 at 01:27:04AM +0000, Justin Dubs wrote:
> You can do it just as you would in perl.  The python equivalent of "last" is
> "break", more or less.
> 
> >>> for i in range(10):
> ...     print i
> ...     if (i == 2):
> ...         break
> 0
> 1
> 2
> 
> Hope this helps,
> 
> Justin Dubs
> 
> "Corey G." <ctgaff at attbi.com> wrote in message
> news:mailman.1022721348.30810.python-list at python.org...
> > 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
> >
> >
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
---end quoted text---

-- 
Best Regards,
Corey





More information about the Python-list mailing list