iterate lines with regex

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Aug 1 16:08:14 EDT 2009


Michael Savarese wrote:
> I'm a python newbie and I'm trying to test several regular expressions on
> the same line before moving on to next line.
> it seems to move on to next line before trying all regular expressions which
> is my goal.
> it only returns true for first regular expression
> does the curser have to be rest to beginning of line? If so, how would I do
> that.
> remember I'm new
> thanks in advance to any advice
> Mike S.
> 
> the following is part of my code,
> readThis=open('c:/9320.txt','r')
> 
> for line in readThis:
>     try:
>         thisKey = key.search(line).group(1)
>         thisMap = map.search(line).group(1)
>         thisParcel = parcel.search(line).group(1)
>     except:
>         continue
> 
> 
The bare except will hide any errors in the lines above it. Either catch 
errors that you expect or take the try-except out.

-- 
Kindest regards.

Mark Lawrence.




More information about the Python-list mailing list