What happens is the different scoping than you would get in, say, C++/Java. There you'd expect i
not to exist between for
s. It's not the case.
You could see that in work, assuming records == 10:
for i in range(records):
filler.apply_proc('AddCompany', gen_add_company())
print("i: %d" % i)
for i in range(records):
filler.apply_proc('AddConference', gen_add_conference())
You'd get in your output - assuming no output from for
:
i: 9
The reason why you're getting the warning is probably that this kind of thing could lead to brain-cracking bugs. Indirect solutions are included in the linked page; one you could consider is to encase your for
in a function, which might be especially good for readability if this happens more than twice.
There's also a similar case of scoping surprise in list comprehensions, but not in Python 3 you're asking about.