Re: [Python-Dev] [Python-checkins] peps: PEP 460: add .format_map()
I'm not sure how format_map helps in porting from 2 to 3, since it doesn't exist in any version of 2. Although that said, it's no doubt a useful feature, just not useful in code that supports both 2 and 3 with a single code base or when porting to 3. Eric. On 1/9/2014 4:02 PM, antoine.pitrou wrote:
http://hg.python.org/peps/rev/8947cdc6b22e changeset: 5341:8947cdc6b22e user: Antoine Pitrou <solipsis@pitrou.net> date: Thu Jan 09 22:02:01 2014 +0100 summary: PEP 460: add .format_map()
files: pep-0460.txt | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/pep-0460.txt b/pep-0460.txt --- a/pep-0460.txt +++ b/pep-0460.txt @@ -24,12 +24,16 @@ similar in syntax to ``str.format()`` (accepting positional as well as keyword arguments).
+* ``bytes.format_map(...)`` and ``bytearray.format_map(...)`` for an + API similar to ``str.format_map(...)``, with the same formatting + syntax and semantics as ``bytes.format()`` and ``bytearray.format()``. +
Rationale =========
In Python 2, ``str % args`` and ``str.format(args)`` allow the formatting -and interpolation of bytes strings. This feature has commonly been used +and interpolation of bytestrings. This feature has commonly been used for the assembling of protocol messages when protocols are known to use a fixed encoding.
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
On 10 January 2014 07:41, Eric V. Smith <eric@trueblade.com> wrote:
I'm not sure how format_map helps in porting from 2 to 3, since it doesn't exist in any version of 2.
Although that said, it's no doubt a useful feature, just not useful in code that supports both 2 and 3 with a single code base or when porting to 3.
It's purely a matter of consistency with str - if we're adding binary interpolation back to Python 3 (which I have been persuaded is a good idea), then we should provide the same three typical spellings of the operation that str provides. Cheers, Nick.
Eric.
On 1/9/2014 4:02 PM, antoine.pitrou wrote:
http://hg.python.org/peps/rev/8947cdc6b22e changeset: 5341:8947cdc6b22e user: Antoine Pitrou <solipsis@pitrou.net> date: Thu Jan 09 22:02:01 2014 +0100 summary: PEP 460: add .format_map()
files: pep-0460.txt | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/pep-0460.txt b/pep-0460.txt --- a/pep-0460.txt +++ b/pep-0460.txt @@ -24,12 +24,16 @@ similar in syntax to ``str.format()`` (accepting positional as well as keyword arguments).
+* ``bytes.format_map(...)`` and ``bytearray.format_map(...)`` for an + API similar to ``str.format_map(...)``, with the same formatting + syntax and semantics as ``bytes.format()`` and ``bytearray.format()``. +
Rationale =========
In Python 2, ``str % args`` and ``str.format(args)`` allow the formatting -and interpolation of bytes strings. This feature has commonly been used +and interpolation of bytestrings. This feature has commonly been used for the assembling of protocol messages when protocols are known to use a fixed encoding.
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On 1/10/2014 10:20 AM, Nick Coghlan wrote:
On 10 January 2014 07:41, Eric V. Smith <eric@trueblade.com> wrote:
I'm not sure how format_map helps in porting from 2 to 3, since it doesn't exist in any version of 2.
Although that said, it's no doubt a useful feature, just not useful in code that supports both 2 and 3 with a single code base or when porting to 3.
It's purely a matter of consistency with str - if we're adding binary interpolation back to Python 3 (which I have been persuaded is a good idea), then we should provide the same three typical spellings of the operation that str provides.
Cheers, Nick.
I'm perfectly okay with that, and it was on my list of things to suggest. I just think that the PEP should be focused on porting code from 2 to 3 and on code that runs on both 2 and 3. I think the Rationale should state this clearly. Eric.
participants (2)
-
Eric V. Smith
-
Nick Coghlan