[Python-ideas] ternary without else
elazarg at gmail.com
Fri May 25 08:57:43 EDT 2018
The title is misleading - this has nothing to do with the conditional
operator, except small syntactic similarity.
בתאריך יום ו׳, 25 במאי 2018, 05:40, מאת Jacco van Dorp <
j.van.dorp at deonet.nl>:
> 2018-05-25 14:26 GMT+02:00 Kirill Balunov <kirillbalunov at gmail.com>:
> > If it is an expression, what should `do_something if cond` return on
> > failure? If you don't care you can already use `cond and do_something`.
> Duh, forgot to mention.
> I wouldn't have it return anything. Ternary returns something because
> you have two options and picks one. This is conditional execution of a
> statement. I guess it would be a statement, like normal if.
> I guess cond and do_something would be equivalent, but that's not
> really the intention of and/or, no matter how much it's used for this
> sort of thing.
> I don't really expect this to be accepted. It's more of a minor gripe
> i've occasionally had. This afternoon, I wrote:
> if not article["art_wt"]: article["art_wt"] = 0
> if not article["px_pchs"]: article["px_pchs"] = 0
> if not article["px_calc"]: article["px_calc"] = 0
> if not article["px_sell"]: article["px_sell"] = 0
> while preparing a dict for import in accountview. I try not to make a
> habit of dismissing syntax warnings. I consider the code above
> abundantly clear (no, I dont know what those keys mean. Since I have
> no power over that, I dont consider it detrimental to clarity.)
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas