[Python-ideas] A "local" pseudo-function

Nikolaus Rath Nikolaus at rath.org
Sun Apr 29 15:17:23 EDT 2018


On Apr 27 2018, Tim Peters <tim.peters-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> Then `c` is 12, but `a` is still 1 and `b` is still 2.  Same thing in the end:
>
> c = local(a=3, b=4, a*b)

I think this can be done already with slighly different syntax:

c = (lambda a=3, b=4: a*b)()


The trailing () is a little ugly, but the semantics are much more
obvious. So maybe go with a variation that makes function evaluation
implicit?

c = lambda! a=3, b=4: a*b

(reads terrible, but maybe someone has a better idea).


> if local(m = re.match(regexp, line)):
>     print(m.group(0))

Of course, that wouldn't (and shouldn't) work anymore. But that's a good
thing, IMO :-).


Best,
-Nikolaus

-- 
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-ideas mailing list