This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients eric.smith
Date 2019-05-02.11:40:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I originally propsed this here:, and there has also been some discussion on discourse.

The proposal is to add a !d "type conversion" to f-strings, to make for simpler "print-based debugging". The idea is that !d would be like !r, etc., except that the resulting string would be:

- the text of the expression, followed by
- an equal sign, followed by
- the value of the expression

So this code:
s = 'A string'
result = f'{s!d}'

Would set result to 's="A string"'.

Note that the text of the expression is exactly what's between the
opening brace and the !. So:
result = f'{s !d}'

Would set result to 's ="A string"'. Note the space before the equal sign.

I can't decide if I'm going to allow a format specifier. If I do, it would apply to the entire resulting string. So:
result = f'{s!d:*^20}'

Would set result to '****s="A string"****'.

But I might reserve format specs for further use, perhaps to apply to the value of the expression instead of the resulting string.

Of course this is of most value for more complex expressions. This:
v = 3
result = f'{v*9+15!d}'

Would set result to 'v*9+15=42'.

I'd expect this mostly to be used with print() or logging, but it's a general f-string feature.

I have a patch almost ready.
Date User Action Args
2019-05-02 11:40:45eric.smithsetrecipients: + eric.smith
2019-05-02 11:40:45eric.smithsetmessageid: <>
2019-05-02 11:40:45eric.smithlinkissue36774 messages
2019-05-02 11:40:45eric.smithcreate