[Python-ideas] Make non-meaningful backslashes illegal in string literals

Chris Angelico rosuav at gmail.com
Sat Aug 8 04:21:46 CEST 2015


On Sat, Aug 8, 2015 at 9:15 AM,  <random832 at fastmail.us> wrote:
> On Fri, Aug 7, 2015, at 01:12, Steven D'Aprano wrote:
>> \P platform-specific newline (e.g. \r\n on Windows, \n on POSIX)
>
> There are not actually a whole hell of a lot of situations that are
> otherwise cross-platform where it's _actually_ appropriate to use \r\n
> on Windows.
>
> How about unicode character names? Say what you will about \xA0 \u00A0
> vs \U000000A0 (and incidentally are we ever going to deprecate octal
> escapes? Or at least make them fixed-width like all the others), but you
> can't really beat \N{NO-BREAK SPACE} for clarity. Of course, you'd want
> a fixed set rather than Perl's insanity with user-defined ones, loose
> ones, and short ones.

Not sure what you're saying here. Python already has those.

>>> ACUTE = "\N{COMBINING ACUTE ACCENT}"
>>> print("Libe{0}re{0}e, de{0}livre{0}e!".format(ACUTE))
Libérée, délivrée!

They do get just a _tad_ verbose, though. Are you suggesting adding
short forms for them, something like:

>>> print("Libe\N{ACUTE}re\N{ACUTE}e, de\N{ACUTE}livre\N{ACUTE}e!")

? Because that might be nice, but then someone has to decide what the
short forms mean. We can always define our own local aliases the way I
did up above; it'd be nice if constant folding could make this as
simple as the \N escapes are, but that's a microoptimization.

ChrisA


More information about the Python-ideas mailing list