diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2004-05-31 19:01:00 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2004-05-31 19:01:00 (GMT) |
commit | 92816de18e3456f8304a1aaa6f28b151858a6e5d (patch) | |
tree | 5ecc10618f570481347e0a9db5b25dccf8c21bb1 /Doc/lib/libdoctest.tex | |
parent | 2a6ba9097ee3942ae328befaf074ce9722b93ca0 (diff) | |
download | cpython-92816de18e3456f8304a1aaa6f28b151858a6e5d.zip cpython-92816de18e3456f8304a1aaa6f28b151858a6e5d.tar.gz cpython-92816de18e3456f8304a1aaa6f28b151858a6e5d.tar.bz2 |
Patch #932930: suggest the use of rawstrings for backslashes.
Diffstat (limited to 'Doc/lib/libdoctest.tex')
-rw-r--r-- | Doc/lib/libdoctest.tex | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index e8983c9..6c72dbc 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -361,17 +361,28 @@ The fine print: \item Output to stdout is captured, but not output to stderr (exception tracebacks are captured via a different means). -\item 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. This is simply because you're in a string, and so - the backslash must be escaped for it to survive intact. Like: +\item If you continue a line via backslashing in an interactive session, + or for any other reason use a backslash, you should use a raw + docstring, which will preserve your backslahses exactly as you type + them: \begin{verbatim} ->>> if "yes" == \\ -... "y" + \\ -... "es": -... print 'yes' -yes +>>> def f(x): +... r'''Backslashes in a raw docstring: m\n''' +>>> print f.__doc__ +Backslashes in a raw docstring: m\n +\end{verbatim} + + Otherwise, the backslash will be interpreted as part of the string. + E.g., the "\textbackslash" above would be interpreted as a newline + character. Alternatively, you can double each backslash in the + doctest version (and not use a raw string): + +\begin{verbatim} +>>> def f(x): +... '''Backslashes in a raw docstring: m\\n''' +>>> print f.__doc__ +Backslashes in a raw docstring: m\n \end{verbatim} \item The starting column doesn't matter: |