<div dir="auto"><div>print(f'{value!d}') is a lot of symbols and boilerplate to type out just for a debugging statement that will be deleted later. Especially now that breakpoint() exists, I can't really see myself using this. </div><div dir="auto"><br></div><div dir="auto">I also don't see the use case of it being within an f-string, because I've never had to interpolate a debug string within some other string or format it in a fancy way. You said it yourself, taking advantage of other f-string features isn't very useful in this case.</div><div dir="auto"><br></div><div dir="auto">If other people can find a use for it, I'd suggest making it ita own function -- debug(value) or something similar.</div><div dir="auto"><br></div><div dir="auto">David </div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr">On Tue, Oct 2, 2018, 8:27 PM Eric V. Smith <<a href="mailto:eric@trueblade.com">eric@trueblade.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This idea was proposed to me at the core sprints last month by Larry <br>
Hastings. I've discussed it with a few people, who seem generally <br>
positive about it, and we've tweaked it a little bit. I've spent some <br>
time implementing it, and I think it's doable. I thought I'd post it <br>
here for any additional feedback.<br>
<br>
Here’s the idea: for f-strings, we add a !d conversion operator, which <br>
is superficially similar to !s, !r, and !a. The meaning of !d is: <br>
produce the text of the expression (not its value!), followed by an <br>
equal sign, followed by the repr of the value of the expression. So:<br>
<br>
value = 10<br>
s = 'a string!'<br>
print(f'{value!d}')<br>
print(f'next: {value+1!d}')<br>
print(f'{s!d}')<br>
<br>
produces:<br>
<br>
value=10<br>
next: value+1=11<br>
s='a string!'<br>
<br>
I’m not proposing this for str.format(). It would only really make sense <br>
for named arguments, and I don’t think <br>
print('{value!d}'.format(value=value) is much of a win.<br>
<br>
The result is a string, so if you really wanted to, you could use a <br>
string formatting spec. So:<br>
<br>
print(f'*{value!d:^20}*'<br>
<br>
would produce:<br>
<br>
*      value=10      *<br>
<br>
Although I don’t think that would be very useful in general.<br>
<br>
The mnemonic is !d for “debugging”. I’d wanted to use !=, because <br>
there’s an equal sign involved in the result, but = is the one character <br>
that can’t be used after ! (it’s “not equal” in expressions, and <br>
f-strings look specifically for that case). I also mentioned !!, but I <br>
think I prefer !d as being less confusing.<br>
<br>
This would be used in debugging print statements, that currently end up <br>
looking like:<br>
<br>
print(f'value={value!r}')<br>
<br>
and would now be:<br>
<br>
print(f'{value!d}')<br>
<br>
There have been discussions about ways to specify str() vs. repr(), <br>
using characters other than '=', adding spaces, etc. But they all end up <br>
over-complicating what should be a simple tool, not a Swiss Army knife.<br>
<br>
Thoughts?<br>
<br>
Eric<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div></div>