A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-January/131244.html below:

[Python-Dev] PEP 460: allowing %d and %f and mojibake

[Python-Dev] PEP 460: allowing %d and %f and mojibake [Python-Dev] PEP 460: allowing %d and %f and mojibakeVictor Stinner victor.stinner at gmail.com
Sun Jan 12 00:11:23 CET 2014
2014/1/11 Ethan Furman <ethan at stoneleaf.us>:
>>> b'x=%s' % 10 is well defined, it's pure bytes.
>>
>> It is well-defined? Then please explain me what the general case of
>>    b'%s' % x
>> is supposed to call:
>
> This is the key question, isn't it?

Python 2 and Python 3 are very different here.

In Python 2, the "s" format of PyArg_Parse may call the __str__()
method of an object.

In Python 3, the "y*" format of PyArg_Parse uses the Py_buffer API
which has no slot (there is no protocol like a __getbuffer__()
method).  The Py_buffer can only be implemented in C. For example,
bytes, bytearray and memoryview implement it. PyArg_Parse requires
also the buffer to be C-contiguous and has a single segment (use
PyBUF_SIMPLE flag).

Said differently, bytes%args and bytes.format() would *not* call any method.

Victor
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4