[Python-ideas] ternary without else
Jacco van Dorp
j.van.dorp at deonet.nl
Mon May 28 02:47:11 EDT 2018
2018-05-26 11:24 GMT+02:00 Antoine Rozo <antoine.rozo at gmail.com>:
> 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
strings in the same dict. (I read out an online database, which only
yields data in json format. I dont want an extra parsing step to
transform it to another data structure than dicts. ). Also, empty
fields are set to None, no matter actual field type(actually, it
doesn't pass empty fields for some godawful reason, so I have a
__missing__ that returns None if and only if it's in a list of
expected fields. ).
As for the dangling else problem, noting a good rule (left to right ?)
and a few parens in other cases can't fix.
That said, because of the rest of this thread, it seems to me like a
statement would be the proper implementation. So the thread title has
become misleading. This would remove the dangling else problem unless
there's an if/else in the condition, which I can't figure out why
you'd need that.
More information about the Python-ideas