As an aside only, it would be pretty reasonable IMO to have

name = value if condition

and set name to None otherwise

But I'm -1 on the idea as I think it's a bit redundant.

Cheers,
-T

On Wed, Apr 8, 2009 at 12:55 AM, spir <denis.spir@free.fr> wrote:
Le Tue, 7 Apr 2009 23:38:21 +1000,
Steven D'Aprano <steve@pearwood.info> s'exprima ainsi:

> > What's the reason why
> >    name = value if condition
> > is invalid? Meaning: there _must_ be an else clause.

> Because "value if condition else other" is an expression, not a
> statement, and thus *must* have a value.
>
>     name = value if condition
>
> only has a value sometimes, and so is invalid [...]

Yes, thank you! That's the explaination I was looking for.
I meant to use the above formulation for updating already defined variables. Indeed, python does not make the difference I have in mind ;-).

As a side note,
  if condition: name = value
(where 'name' is already registered) is the only case when I do not indent a block, for the reason that it means for me the same as the above invalid one-liner.

Denis
------
la vita e estrany
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas



--
--------------------------------------------------
Tennessee Leeuwenburg
http://myownhat.blogspot.com/
"Don't believe everything you think"