tim.peters at gmail.com
Tue Jul 20 04:04:11 CEST 2004
[Edward K. Ream]
> Arggh. I failed to find the following from the docs the first time around:
> "If you continue a line via backslashing in an interactive session, or for
> any other reason use a backslash, you need to double the backslash in the
> docstring version."
Note that "the rules" here follow inescapably from the mechanics of
how doctests are written: first Python processes escapes as part of
compiling the file containing doctests, and then doctest later sends
the strings thru compile(), which processes escapes again.
A sometimes (very) useful alternative is to put doctests in
triple-quoted r-strings. Then Python leaves all the backslashes alone
when compiling the file. If you have a lot of backslashes in
doctests, that can make life a lot easier.
More information about the Python-list