import re
fi = open('/somefile','r') ## Don't do readlines and bring the whole file in memory...
match1 = re.compile('^Python')
match2 = re.compile('^/tBLAH')
prevline = ''
for line in fi:
if match1.search(line) and match2.search(line):
do_something()
prevline = line
fi.close()
HTH, Jacob
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@python.org http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor