[Python-ideas] Add \e escape code

Joshua Landau joshua.landau.ws at gmail.com
Tue Jun 11 20:59:07 CEST 2013


On 11 June 2013 19:36, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Jun 12, 2013 at 4:16 AM, M.-A. Lemburg <mal at egenix.com> wrote:
>> How would you add a new escape character in a backwards compatible
>> way ?
>>
>> Adding new escape characters is not easy, since Python defaults
>> to passing them through as-is, e.g. '\e' == '\\e'.
>
> My understanding of [1] is that the feature of keeping them unchanged
> is meant to be a debugging aid, not something you depend on. Use of
> unescaped backslashes in non-raw string literals is already dangerous
> to editing (if someone changes your Windows path name to c:\testing,
> your code is broken). If a new version breaks someone's non-raw
> literal "c:\everything", it was already broken.
>
> [1] http://docs.python.org/3/reference/lexical_analysis.html#literals

Reading that I see no specific mention that an auto-escaped backslash
is incorrect -- just that it is useful for debugging.

I have also read that they were put in place largely to make it
difficult to add new escapes to prevent an unwanted proliferation of
them. I see no reason for a quick "\e" where "\N{ESCAPE}" works and
whenever you'll want a lot there's a weird circumstance involved
better served by a quick library (as I've done above).


More information about the Python-ideas mailing list