escape sequences and string comparisons

Tim Peters tim.one at home.com
Tue Jan 9 13:52:50 EST 2001


All the *interesting* questions here were already answered by /F, so I'll be
a drudge:

[jkndeja at my-deja.com]
> My copy of K & R C (2nd Ed, Sec A2.5.2) says 'if the character
> following the \ is not one of those specified, the behaviour is
> undefined'
>
> My copy of 'The C Reference Manual' (Harbison and Steele), says
> (paraphrased) '... the behaviour is undefined, though traditionally
> the effect is simply that the backslash is ignored'.

While the latest C std (C99) says

    ...
    If any other character follows a backslash, the result is not
    a token and a diagnostic is required.  See ‘‘future language
    directions’’ (6.11.1).

which latter says

    6.11.1 Character escape sequences
    Lowercase letters as escape sequences are reserved for future
    standardization.  Other characters may be used in extensions.

Right or wrong, at least Guido is Unchangeable <wink>.

BTW, there's another reason (besides easing debugging) Python leaves the
backslashes in:  at the start, r-strings didn't exist, and Emacs-style
regexp syntax was popular.  The latter often requires escaping non-letters,
and e.g.

    "\(.*\)"

is less a pain to type than

    "\\(.*\\)"

just-another-regexp-memory-ly y'rs  - tim





More information about the Python-list mailing list