Hmm, this would be a good use of itertools.tee() (Python 2.4 only):

import itertools
iter1, iter2 = itertools.tee(open('/somefile', 'r'))
iter2.next()
for line, next_line in izip(iter1, iter2):
  ...

Kent

Pierre Barbier de Reuille wrote:
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  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor

Reply via email to