On 2020-06-30 13:25, Chris Angelico wrote:
On Tue, Jun 30, 2020 at 2:28 PM MRAB <pyt...@mrabarnett.plus.com> wrote:
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.
Be careful of semantics here. I'm not sure which languages do what,
but I just checked Perl, and "\x{1234}" is equivalent to Python's
"\u1234", not to "\x12\x34". This proposal is for the latter, which
could be sneakily confusing to someone who also writes in Perl.
MRAB, can you name other languages that use this form?
Ah, right. I missed that bit. That's what happens if you post when you
should be sleeping!
I was just referring to \x{...} as used in Perl, etc.
I suppose that "\x{DEAD BEEF}" could also mean "\x{DEAD}\x{BEEF}" or
"\uDEAD\uBEEF".
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/O7DGH4PJUG4USCDX4VX5MKWZG357DI2M/
Code of Conduct: http://python.org/psf/codeofconduct/