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

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Tue Feb 8 16:55:36 CET 2005


MMmh ... one way to do that :

Py> file_content = open('/somefile', 'r').readlines()
Py> next_file_content = iter(file_content)
Py> next_file_content.next()
Py> for (line, next_line) in izip(file_content, next_file_content):
Py>         match_one = re.search('^Python', line)
Py>         match_two = re.search('^\tBLAH', line)
Py>         if match_one and nextline == match_two:
Py>                do_something()

Pierre

Tom Tucker a écrit :
> Hello! How can I instruct Python to match on the current line and the
> next line?
> 
> 
> Assumptions;
> - We are reading in one line at a time
> 
> 
> 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()
> 
> 
> Maybe this just isn't possible, since we are working line by line. 
> 
> Any suggestions? 
> 
> 
> Tom
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68


More information about the Tutor mailing list