[Python-Dev] Easier debugging with f-strings
Steven D'Aprano
steve at pearwood.info
Tue May 7 20:39:37 EDT 2019
Disclaimer: this topic seems to have been split over at least two issues
on the bug tracker, a Python-Ideas thread from 2018, Discourse (I
think...) and who knows what else. I haven't read it all, so excuse me
if I'm raising something already discussed.
On Mon, May 06, 2019 at 08:39:41PM -0400, Eric V. Smith wrote:
> After that lightning talk, Larry and I talked about it some more, and
> for a number of reasons decided that it would make more sense if the
> syntax used an = sign. So we came up with f"{foo=}", which would also
> produce "foo='Hello'".
>
> The reasons for the change are:
> - Having '=' in the expression is a better mnemonic than !d.
> - By not using a conversion starting with !, we can compose = with the
> existing ! conversions, !r, !s, and the rarely used !a.
> - We can let the user have a little more control of the resulting string.
You're going to hate me for bike-shedding, but I really don't like using
= as a defacto unary postfix operator. To me, spam= is always going to
look like it was meant to be spam==<something> and the second half got
accidentally deleted.
I don't have a better suggestion, sorry.
In an earlier draft, back when this was spelled !d, you specifically
talked about whitespace. Does this still apply?
spam = 42
f'{spam=}' # returns 'spam=42'
f'{spam =}' # returns 'spam =42'
f'{spam = }' # returns 'spam = 42' I guess?
f'{spam+1=}' # returns 'spam+1=41' I guess?
--
Steven
More information about the Python-Dev
mailing list