Raw string fu
Jaime Wyant
programmer.py at gmail.com
Wed Oct 26 14:21:24 EDT 2005
This URL has a good section on raw strings.
http://www.ferg.org/projects/python_gotchas.html
r'\' is wrong because raw strings were originally added to make
regular expressions easier to write. And you can't have a regexp that
ends with \.
Also, you can use the \ to escape your original quote character.
>>> r'I can\'t end strings with a \''
"I can\\'t end strings with a \\'"
hth
jw
On 10/26/05, Joshua Ginsberg <listspam at flowtheory.net> wrote:
> >>> r'\'
> File "<stdin>", line 1
> r'\'
> ^
> SyntaxError: EOL while scanning single-quoted string
> >>> r'\\'
> '\\\\'
>
> Does that seem wrong to anybody else? Shouldn't the first one be
> syntactically correct?
>
> -jag
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list