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

Chris Angelico rosuav at gmail.com
Wed Oct 3 04:34:04 EDT 2018


On Wed, Oct 3, 2018 at 5:54 PM Steven D'Aprano <steve at pearwood.info> wrote:
> I'm not so sure that it only makes sense for named arguments. I think it
> works for arbitrary expressions too:
>
> f'{len("NOBODY expects the Spanish Inquisition!")!d}'
>
> ought to return
>
> 'len("NOBODY expects the Spanish Inquisition!")=39'
>
> which I can see being very useful in debugging expressions.

Absolutely! I can't imagine doing *hugely* complex expressions, but consider:

print(f"{request.args!d}")

Technically that's an "arbitrary expression" and is most definitely
not a named argument, but it's the sort of thing where you really do
want the tag to say "request.args" and not just "args" or anything
like that. Ideally, I'd like to be able to write this as:

dump(request.args)

and have it pick up both the string "request.args" and the value of
request.args, but the f-string variant is absolutely okay with me as a
partial solution.

ChrisA


More information about the Python-ideas mailing list