[Python-ideas] 'where' statement in Python?

Alex Light scialexlight at gmail.com
Tue Jul 20 20:56:38 CEST 2010

i would suggest overloading the 'with', 'as' combo

c = sqrt(a*a + b*b) with:
    get_a(), get_b() as a, b


c = sqrt(a*a + b*b) with:
    get_a() as a
    get_b() as b

it reads well and plus it follows since this statement acts similarly to a
regular with and as statement with the behavior of the context manager being
(in psudocode):
set up: store original value of variable if any and set variable to new
tear down: set value back to original or delete from local namespace if it
never had one

additionally we do not need to introduce any new keywords

any way that this is implemented though it would be quite useful

On Tue, Jul 20, 2010 at 2:35 PM, George Sakkis <george.sakkis at gmail.com>wrote:

> On Tue, Jul 20, 2010 at 8:29 PM, Daniel Stutzbach
> <daniel at stutzbachenterprises.com> wrote:
> > On Tue, Jul 20, 2010 at 1:16 PM, Guido van Rossum <guido at python.org>
> wrote:
> >>
> >> Given the large number of Python users familiar with SQL compared to
> >> those familiar with Haskell, I think we'd do wise to pick a different
> >> keyword instead of 'where'. I can't think of one right now though.
> >
> > Taking a cue from mathematics, how about "given"?
> >
> > c = sqrt(a*a + b*b) given:
> >     a = retrieve_a()
> >     b = retrieve_b()
> Or if we'd rather overload an existing keyword than add a new one,
> "with" reads well too.
> George
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100720/31796c6c/attachment.html>

More information about the Python-ideas mailing list