Re: [Python-ideas] ternary without else

2018-05-27 Thread Jacco van Dorp
2018-05-26 11:24 GMT+02:00 Antoine Rozo : > Dismiss my message, I have read `if "art_wt" not in article`. But in the > same way, you could have a function to reset a value in your dict if the > current value evaluates to False. That won't work, since at other places, I do the same with bools and s

Re: [Python-ideas] ternary without else

2018-05-26 Thread Antoine Rozo
Dismiss my message, I have read `if "art_wt" not in article`. But in the same way, you could have a function to reset a value in your dict if the current value evaluates to False. 2018-05-26 11:21 GMT+02:00 Antoine Rozo : > > if not article["art_wt"]: article["art_wt"] = 0 > > if not article["px_

Re: [Python-ideas] ternary without else

2018-05-26 Thread Antoine Rozo
> 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 I think what you need is the setdefault method of dictionnaries, instead of a new syntax con

Re: [Python-ideas] ternary without else

2018-05-25 Thread Carl Smith
​You cannot have `expression if expression` in a language that also supports `expression if expression else expression` (like Python).​ Otherwise, you have the dangling else problem: https://en.wikipedia.org/wiki/Dangling_else -- Carl Smith carl.in...@gmail.com On 25 May 2018 at 15:21, Rob Cliff

Re: [Python-ideas] ternary without else

2018-05-25 Thread Rob Cliffe via Python-ideas
On 25/05/2018 12:38, Steven D'Aprano wrote: PEP 8 is not holy writ. Ignore it when your code is better for ignoring it. +1.  Not infrequently I judge that my code is easier both to read and to maintain with more than 1 (short) statement on a line, often when it allows similar items to be al

Re: [Python-ideas] ternary without else

2018-05-25 Thread Jacco van Dorp
2018-05-25 14:57 GMT+02:00 Elazar : > The title is misleading - this has nothing to do with the conditional > operator, except small syntactic similarity. On second look, yeah, you're right. ___ Python-ideas mailing list Python-ideas@python.org https://m

Re: [Python-ideas] ternary without else

2018-05-25 Thread Steven D'Aprano
On Fri, May 25, 2018 at 12:06:42PM +0200, Jacco van Dorp wrote: > I would like to carefully suggest a half form of the ternary expression. [...] > However, this isn't PEP8 compliant PEP 8 is not holy writ. Ignore it when your code is better for ignoring it. > I would very much like to write: >

Re: [Python-ideas] ternary without else

2018-05-25 Thread Elazar
The title is misleading - this has nothing to do with the conditional operator, except small syntactic similarity. Elazar בתאריך יום ו׳, 25 במאי 2018, 05:40, מאת Jacco van Dorp ‏< j.van.d...@deonet.nl>: > 2018-05-25 14:26 GMT+02:00 Kirill Balunov : > > If it is an expression, what should `do_som

Re: [Python-ideas] ternary without else

2018-05-25 Thread Jacco van Dorp
2018-05-25 14:26 GMT+02:00 Kirill Balunov : > 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 op

Re: [Python-ideas] ternary without else

2018-05-25 Thread Kirill Balunov
2018-05-25 13:06 GMT+03:00 Jacco van Dorp : > [...] > > I would very much like to write: > > >>> do_something if cond > > and be done with it. Like a ternary expression but without the else clause. > > If it is an expression, what should `do_something if cond` return on failure? If you don't care

Re: [Python-ideas] ternary without else

2018-05-25 Thread Philipp A.
in jinja, you can do “{{ 'foo' if bar }}”. it evaluates to “'foo'” or an empty string (differently to python’s formatting, “None” expands to an empty string in jinja) similarly I often do “thing = 'foo' if bar else None” and it would be nice if i could shorten that by making “else None” implicit.

Re: [Python-ideas] ternary without else

2018-05-25 Thread Serhiy Storchaka
25.05.18 13:06, Jacco van Dorp пише: I would like to carefully suggest a half form of the ternary expression. Currently, you can write code like: if cond: do_something However, especially if the condition and action are both really simple, taking two lines feels like a bit of a waste. So

[Python-ideas] ternary without else

2018-05-25 Thread Jacco van Dorp
I would like to carefully suggest a half form of the ternary expression. Currently, you can write code like: >>> if cond: >>>do_something However, especially if the condition and action are both really simple, taking two lines feels like a bit of a waste. So I sometimes write: >>> if cond: