[Tutor] Match on current line and next line. Possible?

Kent Johnson kent37 at tds.net
Tue Feb 8 16:53:00 CET 2005


Tom Tucker wrote:
> Hello! How can I instruct Python to match on the current line and the
> next line?
> BROKEN EXAMPLE (discussion)
> ######################
> file = open('/somefile','r').readlines()
> for line in file:
>         match_one = re.search('^Python', line)
>         match_two = re.search('^\tBLAH', line)
>         if match_one and nextline == match_two: 
>                do_something()
> 

match_one = None
for line in open(...):
   match_two = re.search('^\tBLAH', line)
   if match_one and match_two:
     do_something()
   match_one = re.search('^Python', line)


Add a last_line variable as well if do_something() needs access to the line data.

Kent



More information about the Tutor mailing list