[Python-ideas] why not "name = value if condition"?
Tennessee Leeuwenburg
tleeuwenburg at gmail.com
Wed Apr 8 00:36:53 CEST 2009
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 at free.fr> wrote:
> Le Tue, 7 Apr 2009 23:38:21 +1000,
> Steven D'Aprano <steve at 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 at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
--
--------------------------------------------------
Tennessee Leeuwenburg
http://myownhat.blogspot.com/
"Don't believe everything you think"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090408/9c221715/attachment.html>
More information about the Python-ideas
mailing list