where clause

Rhodri James rhodri at wildebst.demon.co.uk
Thu Feb 5 19:57:05 EST 2009


On Thu, 05 Feb 2009 18:04:35 -0000, <bearophileHUGS at lycos.com> wrote:

> p = a / b
>   where
>     a = 20 / len(c)
>     b = foo(d)

You'd want to do it with paired keywords, in the manner of try/except,
to avoid utterly breaking Python's syntax conventions.  Perhaps
something like this:

do:
   p = a / b
where:
   a = 20 / len(c)
   b = foo(d)

or even:

where:
   a = 20 / len(c)
   b = foo(d)
do:
   p = a / b


Effectively you're creating a little local namespace for temporary
variables.  I'm not sure it buys you a lot, even as sugar, and I'm
really not convinced by the bypartite form, but it's definitely
possible.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list