Simple Python class defintion not working
<p>In the below code, the compiler is giving me the error "Local variable shouldStoreData" referenced before assingment. But I am assigning it first. Can someone let me know my mistake</p>

<pre><code>class MyHTMLParser(HTMLParser):
    shouldStoreData = False
    textPartDoc = ""
    def handle_starttag(self, tag, attrs):
        print "Encountered a start tag:", tag
        if(tag == "title" or tag == "body"):
            shouldStoreData = True
    def handle_endtag(self, tag):
        print "Encountered an end tag :", tag        
    def handle_data(self, data):
        #print "Data is",data
        #print "valus of storeData is:",shouldStoreData
        if(shouldStoreData == True):
            textPartDoc  = textPartDoc + " " + data
            shouldStoreData = False
</code></pre>

<p>What i am trying to do here is that I want to store the data only when the tag is title or any tag within body</p>
