Obviously, if we do this, the counter will remain at 0 as it is reset at the start of every iteration:
for thing in stuff:
count = 0
print count
count =+1
write_f.write(thing)
But as I have this code inside of function, it does not work to do this either:
count=0
for thing in stuff:
print count
count =+1
write_f.write(thing)
I have several different indent levels, and no matter how I move count=0
about, it either is without effect or throws UnboundLocalError: local variable 'count' referenced before assignment
. Is there a way to produce a simple interation counter just inside the for loop itself?