[Python-Dev] nested scopes confusion
Tue, 4 Dec 2001 20:35:19 +0100
I would have expected the following code to print
1, 2, ..., 9. Instead it prints 25, 25, 25, .. 25.
result = 
for i in range(10):
def mth(*args): return i
i = 25
for mth in functions():
Reading PEP227, I can (barely) understand why it behaves this way.
How do I achieve the desired effect? Note that the default argument
trick (def mth(i=i): ...) does not work because *args is present.