[Python-ideas] Allow lambda decorators

spir denis.spir at free.fr
Mon Feb 9 19:05:54 CET 2009

Le Mon, 9 Feb 2009 09:09:18 -0800,
Guido van Rossum <guido at python.org> a écrit :

>   fs = []
>   for new i in range(10):
>     def f():
>       return i
>     fs.append(f)

The difference I see between such an iteration-specific loop variable and a "declarative" version is that in the latter case it is possible to choose which name(s), among the ones that depend on the loop var, will actually get one "cell" per iteration -- or not. Hem, maybe it's not clear...

For instance, using a declaration, it may be possible to write the following loop (I do not pretend 'local' to be a good lexical choice ;-):

funcs = []
for item in seq:
	local prod	# this name only is iteration specific
	prod = product(item)	# ==> one prod per item
	def f():
		return prod
	if test(item):
		final = whatever(item)	# non-local name
print "func results:\n%s\nend result:%s" \
	%([f() for f in funcs],final)

I do not like global & non-local declaration (do not fit well the overall python style, imo). So I would not like such a proposal, neither. But I like the idea to select names rather than a loop-level on/off switch.

la vida e estranya

More information about the Python-ideas mailing list