[Python-ideas] Allow lambda decorators

Arnaud Delobelle arnodel at googlemail.com
Mon Feb 9 20:13:12 CET 2009


2009年2月9日 Guido van Rossum <guido at python.org>:
> Define new 'for' syntax so that you can write
>> [lambda: i for new i in range(10)]
>> or e.g.
>> fs = []
> for new i in range(10):
> def f():
> return i
> fs.append(f)
>> The rule would be that "for new <name> in ..." defines a new "cell"
> each time around the loop, whose scope is limited to the for loop. So
> e.g. this wouldn't work:
>> for new i in range(10):
> if i%7 == 6:
> break
> print i # NameError

Cool! I'll be able to introduce a new scope at the drop of a hat with
a new handy 'idiom':
def foo(x):
 a = x + 1
 for new a in a**2,:
 print a
 print a
>>> foo(5)
36
6
>>>
-- 
Arnaud


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /