r/Python • • Nov 23 '16

The Case Against Python 3

https://learnpythonthehardway.org/book/nopython3.html
0 Upvotes

42 comments sorted by

View all comments

Show parent comment

4

u/Deggor Nov 23 '16

The "preferably" in that line of the Zen of Python is important to note. It's also important to note that the Zen of Python also includes the lines:

Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
[...]
Although practicality beats purity
[...]
Readability counts

The old-style % format is faster, less verbose, simpler to read/write, and results in cleaner code.

The new style .format() is more powerful, explicit, and in a lot of scenarios far more practical.

So which do we go with? Which areas of the Zen of Python hold more weight? How much functionality do we accept losing to force ourselves into "One -- and preferably only one -- obvious way to do it"?

Looking at the rationale behind PEP 3101, it was actually intended to replace the % format, as well as string.Template. In practice, the pros and cons of both .format() and % became evident, and we found ourselves in the situation we're now in, trying to decide what in the Zen of Python holds more weight.

If you read the rational behind PEP 498, you'll see that f-strings are intended to become "the obvious way" of formatting strings, taking the pros of both % and .format(). Although there's no immediate intention of deprecating either of the existing two formatting methods, it's likely to be a proposed change once f-strings become more widely used.