Is there a way in Python to automatically add an iteration counter to a while loop?
I would like to delete the line count = 0and count += 1in the following code fragment, but still be able to count the number of iterations and test using boolean elapsed < timeout:
import time
timeout = 60
start = time.time()
count = 0
while (time.time() - start) < timeout:
print 'Iteration Count: {0}'.format(count)
count += 1
time.sleep(1)
source
share