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
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_
> 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
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
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
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
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:
>
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
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
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
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.
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
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:
13 matches
Mail list logo