[Python-ideas] Strings can sometimes convert to bytes without an encoding

Terry Reedy tjreedy at udel.edu
Tue Jun 14 20:34:47 EDT 2016


On 6/14/2016 6:58 PM, Franklin? Lee wrote:
> Current behavior (3.5.1):
>     >>> bytes('')
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     TypeError: string argument without an encoding

A null case is the only case where an encoding is not needed, but having 
a special rule is not worth the trouble.

> Suggestion:
> If the character size is 1, the `bytes`/`bytearray` constructor
> doesn't need a specified encoding.

By character size, I presume you mean the PEP 393 internal 1,2,4 bytes 
per char.  Non-ascii latin-1 chars can also be size 1.  Not all 
encodings are ascii compatible.  For example, IBM's EBCDIC.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list