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
Le Tue, 7 Apr 2009 23:38:21 +1000,
Steven D'Aprano <steve@pearwood.info> s'exprima ainsi:
> only has a value sometimes, and so is invalid [...]
> > 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
>
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