title: python 3 local variable defined in enclosing scope referenced before assignment
body: <p>I have declared global variables that i need to access and modify in a function in a class. This function loops indefinitely once called and stream data passes through it. I need to be able to use x y z variables inside the function, and redefine their values as stream_data comes through.
  My current code looks like this:</p>
  <pre><code>x = 10
  y = 8
  z = 2
  class Program():
      def function(stream_data):
          while True:
              try:               
                  a = stream_data['data']
                  if (a - z) &gt; y:
                      y = a - z
                  else:
                      pass
              except:
                  continue
  </code></pre>
  <p>I get error &quot;local variable y defined in enclosing scope on line 7 referenced before assignment&quot;.
  How can I format this code so that when the function is first called, it uses the global variables, and then on each subsequent calling it uses the variable y it redefined? Thanks I am new to coding and really need help!</p>