matching one time through a loop
Justin Dubs
jtdubs at eos.ncsu.edu
Wed May 29 21:27:04 EDT 2002
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
>
>
More information about the Python-list
mailing list