I am using the following function to generate a static variable in Python:
#Static variable generator function
def static_num(self):
k = 0
while True:
k += 1
yield k
When I am calling this function from main code:
regression_iteration = self.static_num()
print " Completed test number %s %s \n\n" % (regression_iteration, testname)
I get this output:
"Completed test number <generator object static_num at 0x027BE260> be_sink_ncq"
Why I am not getting an incremented integer? Where is my static variable generator going wrong?
Edit:
I am calling the function static_num in the following manner now:
regression_iteration = self.static_num().next()
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