title: Python static variable generator function
body: <p>I am using the following function to generate a static variable in Python:</p>
  
  <pre><code> #Static variable generator function
  def static_num(self):
      k = 0
      while True:
          k += 1
          yield k
  </code></pre>
  
  <p>When I am calling this function from main code:</p>
  
  <pre><code> regression_iteration = self.static_num()
   print " Completed test number %s  %s \n\n" % (regression_iteration, testname)
  </code></pre>
  
  <p>I get this output:</p>
  
  <pre><code>  "Completed test number &lt;generator object static_num at 0x027BE260&gt;  be_sink_ncq"
  </code></pre>
  
  <p>Why I am not getting an incremented integer? Where is my static variable generator going wrong?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I am calling the function static_num in the following manner now:</p>
  
  <pre><code>regression_iteration = self.static_num().next()
  </code></pre>
  
  <p>But it returns only '1' since the value of 'k' is being initialized to zero every time the function is called. Therefore, I do not get the required output 1,2,3,4 .... on every call of the function</p>