[Python-ideas] One way to do format and print

Sven R. Kunze srkunze at mail.de
Thu Sep 10 00:45:11 CEST 2015


On 09.09.2015 23:50, Andrew Barnert wrote:
> And if not the docs, what else would it mean to "de-emphasize" %-formatting without deprecating or removing it?

The docs are most important. Sorry, if that didn't come across clearly.

>
>> Anyway, Google presented me the version 2.7 of the tutorial.
> That's a whole other problem. But nobody is going to retroactively change Python 2.7 just to help people who find the 2.7 docs when they should be looking for 3.5.

The Python docs are not Python. So, what's in the way of adding this 
note to Python 2.7 docs? The pride of the Python core devs? I anticipate 
better of you.

> That might seem reasonable today, when 2.7 could heartily recommend str.format because it's nearly the same in 2.7 as in 3.5, but what about next year, when f-strings are the preferred way to do it in 3.6? If 3.6 de-emphasizes str.format (as a feature used only when you need backward compat and/or dynamic formats) and its tutorial, %-formatting docs, and str.format docs all point to f-strings, having 2.7's docs point people to str.format will be misleading at best for 3.6, but having it recommend something that doesn't exist in 2.7 will be actively wrong for 2.7.

str.format teaches people how to use {}. That should be encouraged.
Switching from str.format to f-strings is going to work like charm. So, 
it's the syntax I am concerned with, not how to execute the magic behind.

> The solution is to get people to the 3.5 or 3.6 docs in the first place, not to hack up the 2.7 docs.

You have absolutely no idea why people use 2.7 over 3.5, right? I 
promise you that is going to take time.

And what could you do in the meantime? Call it hacking; to me it's 
improving.

>
>> I still don't understand what's wrong with deprecating %, but okay.
> Well, have you read the answers given by Nick, me, and others earlier in the thread? If so, what do you disagree with?

All "blockers" I read so far classify as a) personal preference of % 
over {} or b) fixable. Both classes do not qualify as real blockers; 
they can be overcome.

> You've only addressed one point (that % is faster than {} for simple cases--and your solution is just "make {} faster", which may not be possible given that it's inherently more hookable than % and therefore requires more function calls...).

Try harder. (If {} is too slow for you.)

I've read Python 3 is significantly slower than Python 2. So what? I can 
live with that, when we will make the transition. If we recognize the 
performance penalty, rest assured I come back here to seek your advice 
but until that it's no reason not to switch to Python 3. Same goes for 
string formatting.

> What about formatting headers for ASCII wire protocols, sharing tables of format strings between programming languages (e.g., for i18n), or any of the other reasons people have brought up?
Both fixable in some way or another, the rest classifies as described above.

Best,
Sven


More information about the Python-ideas mailing list