Eric V. Smith added the comment:
I'm going to close this. Either this problem is going to be addressed
independently of this issue, or it's never going to be fixed. Either way, we
don't need this issue to be open in order to come to a resolution.
--
resolution: -> postponed
stage:
Anselm Kiefner added the comment:
Heh. I had a hunch it could be jupyter specific, but didn't test it. They had
problems with f-strings before, it seems they over-fixed those ..
Maybe you want to check their implementation and see if it's any good for a
general solution?
Otherwise I'd volunteer
Eric V. Smith added the comment:
That code is an error in Python 3.6:
>>> f"{eval('bool(0)\
... and True\
... ')}"
File "", line 3
SyntaxError: f-string expression part cannot include a backslash
>>>
I'm not sure it's a good idea that jupyter accepts code that's not valid in
Python itself.
Anselm Kiefner added the comment:
Hey Eric, just a heads up.
In the latest jupyter notebook, this is valid code:
f"{eval('bool(0)\
and True\
')}"
which returns
'False'
I don't know how far you want to go, but if someone REALLY wants to use
backspace in f-strings just for the sake of it - how
Eric V. Smith added the comment:
I'm thinking that instead of supporting backslashes in general inside
expressions, I'll just special case strings.
So:
f"{'\n' if foo else ''}"
would be okay, but not:
f"{a\
}"
I think that would address the reason why \ was disallowed, but I'm going to
have t
Eric V. Smith added the comment:
The reason that this was done was to give us flexibility in deciding how the
backslashes should be interpreted in the future. I announced it on python-dev
here: https://mail.python.org/pipermail/python-dev/2016-August/145979.html.
That message contains a link t
New submission from Anselm Kiefner:
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