escape sequences and string comparisons

Fredrik Lundh fredrik at effbot.org
Tue Jan 9 04:49:28 EST 2001


jkndeja at my-deja.com wrote:
> whereas I'd want this character to be escaped "\]" in order to be used
> within an RE.

in a previous post, you wanted the character to be escaped
so you could "compare strings with potentially non-alphanumeric
characters"

since that doesn't really make sense (Python can compare non-
alphanumeric characters all by itself), maybe you should explain
what you're really trying to do here...

> Python doesn't seem to follow this. I will investigate further...

it's all in the fine manual:

    http://www.python.org/doc/current/ref/strings.html

    "2.4.1 String literals"

    "Unlike Standard C, all unrecognized escape sequences
    are left in the string unchanged, i.e., the backslash is
    left in the string"

(note that string literals are the things you write in your
Python source code.  They're converted to string values
according to the rules in section 2.4.1.  The strings you
pass to "re" are string values, and are converted to regular
expressions according to the rules in the library reference)

Cheers /F





More information about the Python-list mailing list