[Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

Stefan Behnel stefan_ml at behnel.de
Wed Jan 8 20:17:21 CET 2014


Victor Stinner, 06.01.2014 14:24:
> Abstract
> ========
> Add ``bytes % args`` operator and ``bytes.format(args)`` method to
> Python 3.5.

Here is a counterproposal. Let someone who needs this feature write a
library that does byte string formatting. That properly handles it, a full
featured tool set. Write it in Cython if you need raw speed, that will also
help in making it run in both Python 2 and Python 3, or in providing easy
integration with buffers like the array module, various byte containers,
NumPy, etc.

I'm confident that this will show that the current Py2 code that
(legitimately) does byte string formatting can actually be improved,
simplified or sped up, at least in some corners. I'm sure Py2 byte string
formatting wasn't perfect for this use case either, it just happened to be
there, so everyone used it and worked around its particular quirks for the
particular use case at hand. (Think of "%s" % some_unicode_value, for example.)

Instead of waiting for 3.5, a third party library allows users to get
started porting their code earlier, and to make it work unchanged with
Python versions before 3.5.

Stefan




More information about the Python-Dev mailing list