search files in python based on header and footer patterns
<p>I would like to parse a file which looks like this:</p>

<pre><code>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
HEADER
body
body
body
FOOTER
BLABLABLABLA
BLABLABLABLA
BLABLABLABLA
</code></pre>

<p>I would like to extract the content that exists between HEADER and FOOTER.
The number of lines between each HEADER and FOOTER can vary and so can the content itself
I have written the following code to extract this:</p>

<pre><code>   fd=open(file,"r")
    for line in fd:
        if not start_flag:
            match = re.search(r'.*HEADER.*',line)
            if not match:
                continue
            else:
                body=body+line+"\n"
                start_flag=True
        else:
            match_end = re.search(r'.*FOOTER.*',line)
            if not match_end:
                body=body+line+"\n"
                continue
            else:
                body=body+line+"\n\n"
                break
   print body
</code></pre>

<p>Is this the best way to go about extracting contents from file using python ?
What are the other ways to go about such a problem ?</p>
