Friday, 15 June 2012

Python static variable generator function -


Code> #Static When I am calling this function with the main code:

 

Code> regression_iteration = self.static_num () print "Full test number%

I get this output:

"The test number is completed" and <% s \ n \ n "% (regress_iteration, testname) 00X027BE260> generator object static_num> be_sink_ncq "

Why me a Where is my fixed variable generator going?

Edit:

I now call function_ static_num in the following manner I am:

  regression_iteration = self.static_num (). Next ()  

But it only returns '1' because the value of 'k' Every time I started calling at zero. Therefore, I do not get the necessary output 1,2,3,4 on each call to the function

It is hard to say that Or you need to need to use this approach - I suspect strongly , but instead of a generator you can abuse by default using unstable types Is the beginning:

  def counter (init = [0]): init [0] + = 1 init [0] x = counter () print (x) # 1 print (x) # 1 print (x) # 1 x = counter () print (x) print value (x) # 2 print (x) # 2 # ... etc  

Return value of < Code> Counter increases from one on each call, starting with 1 It is.


No comments:

Post a Comment