This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Anselm Kiefner
Recipients Anselm Kiefner
Date 2017-06-28.18:58:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:13Anselm Kiefnersetrecipients: + Anselm Kiefner
2017-06-28 18:58:13Anselm Kiefnersetmessageid: <>
2017-06-28 18:58:13Anselm Kiefnerlinkissue30793 messages
2017-06-28 18:58:13Anselm Kiefnercreate