[Python-Dev] PEP 461 - Adding % and {} formatting to bytes
Brett Cannon
brett at python.org
Wed Jan 15 23:17:24 CET 2014
On Wed, Jan 15, 2014 at 4:24 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 01/15/2014 06:45 AM, Brett Cannon wrote:
>
>>
>> I also think that a 'b' conversion be added to bytes.format(). This
>> doesn't have the same issue as %b if you make {}
>> implicitly mean {!b} in Python 3.5 as {} will mean what is the most
>> accurate for bytes.format() in either version. It
>> also allows for explicit support where you know you only want a byte and
>> allows {!s} to mean you only want a string (and
>> thus throw an error otherwise).
>>
>
> Given that !b does not exist in Py2, !s (like %s) has to mean bytes when
> working with a byte stream. Given that, !s and !b would mean the same
> thing, so it worth adding !b?
>
I disagree with the assertion. %s has to mean bytes for Python 2
compatibility because there is no equivalent to '{}' (no conversion or
format spec specified); basically %s represents "no conversion" for the %
operator. But since format() has the concept of a default conversion as
well as explicit conversions you can lean on that fact and let the default
conversion do what makes sense for that version of Python.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140115/9241cd5d/attachment-0001.html>
More information about the Python-Dev
mailing list