PEP 467: add more explanation to `bytes.ascii()`
This commit is contained in:
parent
c85dbf3c8e
commit
b9655e3ba7
10
pep-0467.txt
10
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
|
||||
------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue