[Python-ideas] Anaphoric if

Jess Austin jess.austin at gmail.com
Sat Apr 24 02:23:50 CEST 2010


On Fri, Apr 23, 2010 at 3:47 PM,  Andrey Fedorov <anfedorov at gmail.com> wrote:
> I imagine this has been covered before, but somehow my Google-foo is
> failing. What are people's opinions about having an anaphoric-if syntax
> sugar like:
>
> if foo() as x:
>    ... x
>
>
> meaning
>
> x = foo()
> if x:
>    ... x
>

I like this, and I'd like for it to be in python, although I don't
think it will be widely supported because it only saves one line, and
the idiom it replaces isn't very common. [Which facts didn't prevent
the adoption of '@' decorator syntax, but I digress...]  A question
for the sake of completeness: would the following:

if not foo() as x:
    ... x

mean this:

x = foo()
if not x:
    ... x


cheers,
Jess



More information about the Python-ideas mailing list