
On Fri, May 27, 2011 at 12:02 PM, INADA Naoki <songofacandy@gmail.com> wrote:
Then, I hope bytes has a fast and efficient "format" method like:
b'{0} {1}'.format(23, b'foo') # accepts int, float, bytes, bool, None 23 foo b'{0}'.format('foo') # raises TypeError for other types. TypeError
What method is invoked to convert the numbers to text? What encoding is used to convert those numbers to text? How does this operation avoid also converting the *bytes* object to text and then reencoding it? Bytes are not text. Struggling against that is a recipe for making life hard for yourself in Python 3. That said, there *may* still be a place for bytes.format(). However, proper attention needs to be paid to the encoding issues, and the question of how arbitrary types can be supported (including how to handle the fast path for existing bytes() and bytearray() objects). The pedagogic cost of making it even harder than it already is to convince people that bytes are not text would also need to be considered.
And line buffering in binary mode is also nice.
The Python 3 IO stack already provides b'\n' based line buffering for binary files. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia