[Python-ideas] f-string "debug" conversion
tim.peters at gmail.com
Wed Oct 3 00:23:15 EDT 2018
[Eric V. Smith <eric at trueblade.com>]
> Here’s the idea: for f-strings, we add a !d conversion operator, which
> is superficially similar to !s, !r, and !a. The meaning of !d is:
> produce the text of the expression (not its value!), followed by an
> equal sign, followed by the repr of the value of the expression.
> The result is a string, so if you really wanted to, you could use a
> string formatting spec. So:
> would produce:
> * value=10 *
> Although I don’t think that would be very useful in general.
Me neither ;-) But what if
acted like the current
? I'd find _that_ useful often. For example, when displaying floats,
where the repe is almost never what I want to see.
I have plenty of code already embedding stuff of the form
and don't really care whether there's a space or an "=" between the
chunks. "!d" could act like a macro-expansion operator automating a
mechanical transformation inside the f-string. Then I could read "!d" as
"duplicate" instead of as "debug" ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas