I'm reading a file and grabbing data. The file is set up into sections that are formatted in different ways. So I'm reading the file and checking each line for a header. When a header is found I set a flag and then if the flag is checked i apply more regex to find the data. When the next header is encountered I change the flags accordingly. The code I have works but I was just curious if there is a more "pythonic" way or easy one liner to set these flags. I'm working on version 2.4.3
Code:
for line in file:
match1 = re.match(r'header1',line)
match2 = re.match(r'header2',line)
match3 = re.match(r'header3',line)
if match1 is not None:
flag1 = True
flag2 = False
flag3 = False
if match2 is not None:
flag1 = False
flag2 = True
flag3 = False
if match3 is not None:
flag1 = False
flag2 = False
flag3 = True
......... rest of code
