escape sequences and string comparisons
jkndeja at my-deja.com
jkndeja at my-deja.com
Mon Jan 8 07:28:02 EST 2001
Hello there
I've just discovered that when using the escape character in a string,
if the following character is _not_ an expected 'escape code'
character, the the backslash is passed on, rather than being dropped,
eg:
len("\'") == 1 # a back-tick
len("\\") == 1 # a quote character
# '\>' doesn't have a meaningful escape value
len("\>") != 1
I was expecting this latter case to give me a single '>' character, but
instead I seem to get a two-character string, '\>'.
Well, OK (although I'm still surprised). But I generated this string
('\>') using re.escape(), in order to compare strings with potentially
non-alphanumeric characters.
Since re.escape() simply uses the criterion of 'non-alphanumeric
character' to determine whether to escape a character, is there an
alternative function to 'escape only characters used in string literal
escapes', am I on my own, or am I missing something?
Thanks
Jon Nicoll
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list