<br><br><div>On Thu Mar 27 2014 at 2:42:40 PM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Much better, but I'm still not happy with including %s at all. Otherwise it's accept-worthy. (How's that for pressure. :-)<br></div></blockquote><div><br></div><div>But if we only add %b and leave out %s then how is this going to lead to Python 2/3 compatible code since %b is not in Python 2? Or am I misunderstanding you?</div>
<div><br></div><div>-Brett</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"></div><div class="gmail_extra"><br><br><div class="gmail_quote">
</div></div><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 27, 2014 at 11:04 AM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><div>On 03/27/2014 10:55 AM, Ethan Furman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 03/27/2014 10:29 AM, Guido van Rossum wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I also don't understand why we can't use %b instead of %s. AFAIK %b currently doesn't mean anything and I somehow don't<br>
expect we're likely to add it for other reasons (unless there's a proposal I'm missing?). Just like we use %a instead of<br>
%r to remind people that it's not quite the same (since it applies .encode('ascii', 'backslashreplace')), shouldn't we<br>
use anything *but* %s to remind people that that is also not the same (not at all, in fact)? The PEP's argument against<br>
%b ("rejected as not adding any value either in clarity or simplicity") is hardly a good reason.<br>
</blockquote>
<br>
The biggest reason to use %s is to support a common code base for 2/3 endeavors. The biggest reason to not include %b<br>
is that it means binary number in format(); given that each type can invent it's own mini-language, this probably isn't<br>
a very strong argument against it.<br>
<br>
I have moderate feelings for keeping %s as a synonym for %b for backwards compatibility with Py2 code (when it's<br>
appropriate).<br>
</blockquote>
<br></div>
Changed to:<br>
------------------------------<u></u>------------------------------<u></u>----------------------<br>
``%b`` will insert a series of bytes. These bytes are collected in one of two<br>
ways:<br>
<br>
- input type supports ``Py_buffer`` [4]_?<div><br>
use it to collect the necessary bytes<br>
<br>
- input type is something else?<br></div>
use its ``__bytes__`` method [5]_ ; if there isn't one, raise a ``TypeError``<br>
<br>
In particular, ``%b`` will not accept numbers nor ``str``. ``str`` is rejected<br>
as the string to bytes conversion requires an encoding, and we are refusing to<br>
guess; numbers are rejected because:<br>
<br>
- what makes a number is fuzzy (float? Decimal? Fraction? some user type?)<br>
<br>
- allowing numbers would lead to ambiguity between numbers and textual<br>
representations of numbers (3.14 vs '3.14')<br>
<br>
- given the nature of wire formats, explicit is definitely better than implicit<br>
<br>
``%s`` is included as a synonym for ``%b`` for the sole purpose of making 2/3 code<br>
bases easier to maintain. Python 3 only code should use ``%b``.<br>
<br>
Examples::<br>
<br>
>>> b'%b' % b'abc'<br>
b'abc'<br>
<br>
>>> b'%b' % 'some string'.encode('utf8')<br>
b'some string'<br>
<br>
>>> b'%b' % 3.14<div><br>
Traceback (most recent call last):<br>
...<br></div>
TypeError: b'%b' does not accept 'float'<br>
<br>
>>> b'%b' % 'hello world!'<div><br>
Traceback (most recent call last):<br>
...<br></div>
TypeError: b'%b' does not accept 'str'<br>
------------------------------<u></u>------------------------------<u></u>----------------------</div></div></blockquote><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><div class="gmail_quote"><br>
<br>
--<br>
~Ethan~<br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br></div></div></blockquote></div></div><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><div class="gmail_quote">
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>guido%40python.org</a><br>
</div></div></blockquote></div></div><div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)
</div>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/brett%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>brett%40python.org</a><br>
</blockquote>