This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author underrun
Recipients Arfrever, arjennienhuis, barry, benjamin.peterson, brett.cannon, christian.heimes, durin42, ecir.hana, eric.smith, exarkun, ezio.melotti, flox, glyph, gregory.p.smith, loewis, martin.panter,, pitrou, serhiy.storchaka, stendec, terry.reedy, tshepang, uau, underrun, vstinner
Date 2014-07-25.17:31:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
First off, +1 for this feature. It's not just for twisted, but anyone doing anything with binary data (storage, compression, encryption and networking for me) with python since 2.6 will very likely have been using .format for building messages. I know I have and obviously others have been doing so as well.

The advantages of .format to me are:

* compatible with 2.6 (porting and single code base support easier)
* ease of composition (the format langauge makes it easy to build complex data structures out of bytes)
* readability (named fields make complex formats obvious)
* consistency (manipulating a block of bytes or characters can be done in a similar way)

Specific comments on the patch supplied by terry.reedy:

* it doesn't support named fields
* it doesn't handle padding
* it doesn't handle nested formats (like '{0:{1}>{2}}'.format(data,pad_char,pad_width)
* formatting byte strings with a width embedds the repr of the byte string ( bf(b'{:>10}', [b'test']) == b"   b'test'" )

Really this isn't a good way to solve the problem.

Has a PEP been created for this? If not how can I help make that happen?

Including this in 3.5 would be so helpful for us low level systems programmers out there who have lots of code using .format for binary interfaces in python 2.6/2.7 already.

Also, not to add to derailment, but if we're adding a .format for python3 bytes it would be great if .format could pad with the null byte ('\0') which it currently converts to spaces internally (which is strange). Since this unexpected conversion is bad (so padding with null doesn't happen in python2) its more like a bug fix... actually - maybe that's a separate bug to file on the current .format for text...
Date User Action Args
2014-07-25 17:31:11underrunsetrecipients: + underrun, loewis, barry, brett.cannon, terry.reedy, gregory.p.smith, exarkun, pitrou, vstinner, eric.smith, christian.heimes, benjamin.peterson, glyph, ezio.melotti, durin42, Arfrever, arjennienhuis, flox, ecir.hana, uau, tshepang, martin.panter, serhiy.storchaka,, stendec
2014-07-25 17:31:11underrunsetmessageid: <>
2014-07-25 17:31:11underrunlinkissue3982 messages
2014-07-25 17:31:11underruncreate