[Python-ideas] f-string "debug" conversion

Tim Peters tim.peters at gmail.com
Wed Oct 3 20:47:45 EDT 2018


[Guido]

> Gah! You are overthinking it. This idea is only worth it if it's dead
> simple, and the version that Eric posted to start this thread, where !d
> uses the repr() of the expression, is the only one simple enough to bother
> implementing.
>

In that case, I have no real use for it, for reasons already explained (I
rarely want the repr, and already have lots of code that tediously repeats
the

    EXPR {EXPR:FMT}

pattern inside f-strings).  Even for displaying integers, where you might
_assume_ I'd be happy with the repr, I'm often not:

    print(f"nballs {nballs:,} into nbins {nbins:,}")

is one I just happened to write today.  Without comma formatting, the
output is much harder to read.

Note that transforming

   {EXPR!d:FMT}

into

   EXPR={repr(EXPR):FMT}

is actually slightly more involved than transforming it into

   EXPR={EXPR:FMT}

so I don't buy the argument that the original idea is simpler.  More
magical and less useful, yes ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181003/ee5f52ad/attachment-0001.html>


More information about the Python-ideas mailing list