On Sun, Oct 23, 2016 at 2:14 PM, Steve D'Aprano <steve+pyt...@pearwood.info> wrote: > There's definitely something strange going on. Compare the what happens when > the semi-global variable is in the first loop iterable versus the second > loop iterable. In this first example, y refers to both the global and the > local, yet strangely there's no error: >
Right. Disassembly shows that it's something like this: y = 6 val1 = [(x,y) for x in range(y) for y in range(3)] def temp(iter): ret = [] for x in iter: for y in range(3): ret.append((x, y)) return ret val2 = temp(iter(range(y))) That first iterable is evaluated in the outer context, then passed as a parameter. ChrisA -- https://mail.python.org/mailman/listinfo/python-list