Message297206
Considering that
x = 3
f"{'hello' if x == 3 else 'goodbye'} world"
is a simple, elegant and powerful piece of code that works just as expected by itself, I often find myself stumbling and wondering why
f"text {'\n' if x == 3 else ''} text"
fails horribly just because of the \ within the extra quoted string that must be worked around with ugly code like
nl = "\n"
f"text {nl if x==3 else ''} text"
which really doesn't feel like python at all.
I am aware that the specification for f-strings says "no \ in expressions", but please consider that in this case, the \ is not really part of the expression but rather part of a string that isn't evaluated as part of the expression, which might just as well be referenced to by a variable. |
|
Date |
User |
Action |
Args |
2017-06-28 18:58:13 | Anselm Kiefner | set | recipients:
+ Anselm Kiefner |
2017-06-28 18:58:13 | Anselm Kiefner | set | messageid: <1498676293.91.0.9735369648.issue30793@psf.upfronthosting.co.za> |
2017-06-28 18:58:13 | Anselm Kiefner | link | issue30793 messages |
2017-06-28 18:58:13 | Anselm Kiefner | create | |
|