Re: lambda construction

Kenneth Manheimer (
Wed, 22 Jun 1994 19:44:11 GMT

Ah! Now (i think) i understand!

> > > > def wrap (ofunc):
> > > > return lambda *args: (process_args(args), apply (ofunc, args))[1]
> > > [guido]
> > > Actually, ofunc is *never* bound inside that lambda! If you were to
> > > call it inside wrap it would also fail. Python is not Lisp!
> > [ken]
> > I suspect i'm being dense. Where am i going astray?
> [tim]
> The simplicity of Python's scoping trips up everyone at first glance, but
> you already wrote up the answer in your fact sheet <wink>: the search
> order is [local, global, builtin], and everything follows from that, +
> that "lambda" is syntactic sugar for a one-line def.
> [...]
> ofunc is not in "temp"'s local ns ("args" is the _only_ name in temp's
> local ns), so it's not in the lambda's local ns, so "ofunc is *never*
> bound inside that lambda!" is correct (assuming "ofunc" isn't in the
> global or builtin namespaces).

I was confused in thinking that the global name space for the lambda
(or your temp function) was the local name space of the wrap function.
You're right, i had even written (and read, and supposedly understood)
that name spaces are not nested. Hopefully, after wading through this
confusion, i've got it now.

Yeah, right.-)

Ken, 301 975-3539