
Well - one can already do: x = bytes.fromhex x("01 23 45 67 89") As for base64, I really, really, don't see a use case where allowing base64 native strings as part oif the syntax could be useful - less so when decoding is one call away. Base64 was already created to allow one to convey arbitrary data as strings - let them be strings, As for the "x" mode: I think the burden - including cognitive when teaching Python - to include new prefix strings easily overcome any gains there might be - again, more so once that a call like `bytes.frohex` is readily available. js -><- On Wed, Nov 23, 2022 at 9:33 AM Ronald Hoogenboom via Python-ideas < python-ideas@python.org> wrote:
Refer to PEP 3137 and PEP 358.
Bytes objects are for conveying binary data (or encoded strings). Such binary data is customary specified in hex-dump or base64 format in source files.
It would be nice to introduce a way in python to do that ‘natively’ (at lexical analysis time) using x-strings and y-strings (in lieu of f-strings).
x-strings:
x”0123456789abcdef” (x-prefixed quoted string of even-numbered amount of characters of the set [0-9a-fA-F], whitespace ignored)
equivalent to:
b”\x01\x23\x45\x67\x89\xab\xcd\xef” (but more readable)
y-strings:
y”ASNFZ4mrze8=” (y-prefixed quoted string of valid base64, whitespace ignored)
equivalent to:
b”\x01\x23\x45\x67\x89\xab\xcd\xef” (but shorter)
This is not a replacement of the hex/base64 encoding, binascii packages etc. It just gives the programmer more freedom to specify literal bytes objects in the source code.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VGXARY... Code of Conduct: http://python.org/psf/codeofconduct/