constructing binary backslash-n
tim.peters at gmail.com
Thu Sep 30 06:27:17 CEST 2004
> Something seemed to screw up my message, putting two backslashes
> everywhere I put only one. That probably led to your confusion. It
> seems that Jeff may have been similarly confused. I'll try again.
> I want to be able to receive a letter like 'n', let's say as user
> input, and generate the single byte escape value of backslash-n or
> ASCII 10, as a string of length 1. If the user provided the letter
> 'r', I would return a string one character long, for which
> ord(my_string) == 13. This should be equivalent to the string
OK, but I still want to know what the notation \[a-z] meant in your
original message. The two examples you gave here are very special,
because backslash + n and backlash + r are two of the few two-letter
sequences that *have* a special meaning in Python (or C) strings. If
the letter is, for example, z, what do you want then? backslash + z
doesn't mean anything special to anyone.
The only letters that have special meaning after a backslash are:
a b f n r t v x
and backslash + x all alone raises ValueError.
More information about the Python-list