From b9655e3ba7cd7e81c2b970fd5ea05ff2c5ac5ec5 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Wed, 3 Nov 2021 23:32:54 -0700 Subject: [PATCH] PEP 467: add more explanation to `bytes.ascii()` --- pep-0467.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pep-0467.txt b/pep-0467.txt index 8bea5319f..ece9bf49c 100644 --- a/pep-0467.txt +++ b/pep-0467.txt @@ -130,6 +130,10 @@ Python 2 ``str``) was as simple as:: With Python 3 that became the more verbose:: + >>> b'%d' % 123 + +or even:: + >>> str(123).encode('ascii') This PEP proposes that an ``ascii`` method be added to ``bytes`` and ``bytearray`` @@ -138,6 +142,12 @@ to handle this use-case:: >>> bytes.ascii(123) b'123' +Note that ``bytes.ascii()`` would handle simple ascii-encodable text correctly, +unlike the `ascii()`` built-in:: + + >>> ascii("hello").encode('ascii') + b"'hello'" + Addition of "getbyte" method to retrieve a single byte ------------------------------------------------------