Python 3 bytes formatting

Ecir Hana picture Ecir Hana · Mar 29, 2013 · Viewed 56.8k times · Source

In Python 3, one can format a string like:

"{0}, {1}, {2}".format(1, 2, 3)

But how to format bytes?

b"{0}, {1}, {2}".format(1, 2, 3)

raises AttributeError: 'bytes' object has no attribute 'format'.

If there is no format method for bytes, how to do the formatting or "rewriting" of bytes?

Answer

Ecir Hana picture Ecir Hana · Mar 28, 2014

And as of 3.5 % formatting will work for bytes, too!

https://mail.python.org/pipermail/python-dev/2014-March/133621.html