PEP 467: ascii constructors removed (GH-3603)
This commit is contained in:
parent
5f200941a3
commit
89f5afbb21
|
@ -20,7 +20,6 @@ This PEP proposes five small adjustments to the APIs of the ``bytes`` and
|
|||
|
||||
* Add ``fromsize`` alternative constructor
|
||||
* Add ``fromint`` alternative constructor
|
||||
* Add ``ascii`` alternative constructor
|
||||
* Add ``getbyte`` byte retrieval method
|
||||
* Add ``iterbytes`` alternative iterator
|
||||
|
||||
|
@ -120,36 +119,6 @@ negative numbers. The documentation of the new methods will refer readers to
|
|||
``int.to_bytes`` for use cases where handling of arbitrary integers is needed.
|
||||
|
||||
|
||||
Addition of "ascii" constructors
|
||||
--------------------------------
|
||||
|
||||
In Python 2 converting an object, such as the integer ``123``, to bytes (aka the
|
||||
Python 2 ``str``) was as simple as::
|
||||
|
||||
>>> str(123)
|
||||
'123'
|
||||
|
||||
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``
|
||||
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