[Python-ideas] One way to do format and print
Stephen J. Turnbull
stephen at xemacs.org
Tue Sep 8 03:44:36 CEST 2015
Chris Angelico writes:
> On Tue, Sep 8, 2015 at 7:00 AM, Andrew Barnert via Python-ideas
> <python-ideas at python.org> wrote:
> > But there will always be cases that % is better for, such as:
[...]
> > * ASCII-based wire protocols or file formats
>
> Supporting this last one is PEP 461. There are no proposals on the
> cards to add a b"...".format() method (it's not out of the question,
> but there are problems to be overcome
Actually, it was proposed and pronounced (immediately on proposal :-).
There were no truly difficult technical problems, but Guido decided it
was a YAGNI, and often an attractive nuisance. In particular, many of
the use cases for bytestring formatting are performance-critical bit-
shoveling applications, and adding a few extra method lookups and
calls to every formatting operation would be a problem. Many others
involve porting Python 2 applications that used str to hold and format
"external" strings, and those use %-formatting, not .format.
> because of the extreme generality of it),
Hm. It seems to me in the PEP 498 discussion that Guido doesn't see
generality as a problem to be solved by restricting it, but rather as
a characteristic of an implementation that makes it more or less
suitable for a given feature. I guess that Guido would insist on
having bytes.format be almost identical to str.format, except maybe
for a couple of tweaks similar to those added to bytes' % operator.
More information about the Python-ideas
mailing list