Global Name 'q' not Defined - Python
<p>I have a program like :</p>

<pre><code>class ABC:

    q = {}

    def update:
        self.state = (xx,xx)
        global q
        if self.state in q:
            // do something
</code></pre>

<p>I am getting the error :</p>

<blockquote>
  <p>"NameError: global name 'q' is not defined"</p>
</blockquote>

<p>Im new to python and need some help.</p>

<p>You can move <em>q</em> outside of the class:</p>

<pre><code>q = {}

class ABC: 

    def update:
        self.state = (xx,xx)
        global q
        if self.state in q:
            # do something
            pass
</code></pre>

<p>or you can reference <em>q</em> as a class variable:</p>

<pre><code>class ABC:

    q = {}

    def update:
        self.state = (xx,xx)
        if self.state in ABC.q:
                # do something
                pass
</code></pre>

python nameerror