Alternative to multi-line lambdas: Assign-anywhere def statements

Devin Jeanpierre jeanpierreda at gmail.com
Sat Jan 24 21:35:03 CET 2015


On Sat, Jan 24, 2015 at 11:55 AM, Chris Angelico <rosuav at gmail.com> wrote:
> That's still only able to assign to a key of a dictionary, using the
> function name. There's no way to represent fully arbitrary assignment
> in Python - normally, you can assign to a name, an attribute, a
> subscripted item, etc. (Augmented assignment is a different beast
> altogether, and doesn't really make sense with functions.) There's no
> easy way to say "@stash(dispatch_table_a['asdf'])" and have that end
> up assigning to exactly that.

Obviously, nobody will be happy until you can do:

def call(*a, **kw): return lambda f: f(*a, **kw)

@call()
def x, y ():
    yield 1
    yield 2

Actually, maybe not even then.

-- Devin



More information about the Python-list mailing list