On Thu, Jul 4, 2013 at 2:30 PM, Joshua Landau
<[email protected]> wrote:
> That said, I'm not too convinced. Personally, the proper way to do
> what you are talking about is creating a new closure. Like:
>
> for i in range(100):
> with new_scope():
> for i in range(100):
> func(i)
> func(i) # Using i from original loop
>
> But it's not like Python'll ever support that.
>
def foo():
for i in range(3):
print("outer",i)
def inner():
for i in range(4):
print("inner",i)
inner()
print("outer",i)
That works, but you then have to declare all your nonlocals, and it
hardly reads well.
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list