How to define a global list in python
<p>I have two methods that should write to the same list.</p>

<pre><code>class MySpider():

    def parse_post(self, response):
        commentList = []
        ...  
        commentList.append(someData)

    def parse_comments(self, response):
        commentList = []
        ...  
        commentList.append(someData)
</code></pre>

<p>In this code there are two commentList lists but I need a single list where I can append data. I want to access this list in any method of this class. I tried with</p>

<pre><code>class MySpider():

    commentNum = []

    def parse_post(self, response):
        ...  
        commentList.append(someData)

    def parse_comments(self, response):
        ...  
        commentList.append(someData)
</code></pre>

<p>But this gives me an error <code>global name commentList is not defined</code>. Any ideas how to have a single list that can be accessed in all methods in that class?</p>
