30 Jun
2020
30 Jun
'20
2:42 a.m.
On 2020-06-30 02:14, Steven D'Aprano wrote: [snip]
Counter-proposal: hex escapes allow optional curly brackets, similar to unicode name escapes. You could even allow spaces within the braces, for grouping:
# Existing: "\N{HYPHEN-MINUS}" # '-' "\x2b" # '+'
# Proposed enhancement: "\x{2b}2c" # '+2c' "\x{2b2c}" # '+,' "\x{DEAD BEEF}" # "\xDE\xAD\xBE\xEF"
This could work in f-strings and bytes as well. I think this might be of use for people who do a lot of work with binary file formats and hex escapes.
I think this is backwards compatible too, since "\x{" is currently a syntax error.
There's a precedent in other languages that use this form instead of \uXXXX and \UXXXXXXXX.