Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
81c26205
Commit
81c26205
authored
May 31, 2004
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #932930: suggest the use of rawstrings for backslashes.
parent
c94e0166
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
21 deletions
+41
-21
Doc/lib/libdoctest.tex
Doc/lib/libdoctest.tex
+20
-9
Lib/doctest.py
Lib/doctest.py
+21
-12
No files found.
Doc/lib/libdoctest.tex
View file @
81c26205
...
@@ -361,17 +361,28 @@ The fine print:
...
@@ -361,17 +361,28 @@ The fine print:
\item
Output to stdout is captured, but not output to stderr (exception
\item
Output to stdout is captured, but not output to stderr (exception
tracebacks are captured via a different means).
tracebacks are captured via a different means).
\item
If you continue a line via backslashing in an interactive session,
or
\item
If you continue a line via backslashing in an interactive session,
for any other reason use a backslash, you need to double the backslash in
or for any other reason use a backslash, you should use a raw
the docstring version. This is simply because you're in a string, and so
docstring, which will preserve your backslahses exactly as you type
the
backslash must be escaped for it to survive intact. Like
:
the
m
:
\begin{verbatim}
\begin{verbatim}
>>> if "yes" ==
\\
>>> def f(x):
... "y" +
\\
... r'''Backslashes in a raw docstring: m
\n
'''
... "es":
>>> print f.
__
doc
__
... print 'yes'
Backslashes in a raw docstring: m
\n
yes
\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}
\end{verbatim}
\item
The starting column doesn't matter:
\item
The starting column doesn't matter:
...
...
Lib/doctest.py
View file @
81c26205
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
"""Module doctest -- a framework for running examples in docstrings.
r
"""Module doctest -- a framework for running examples in docstrings.
NORMAL USAGE
NORMAL USAGE
...
@@ -200,16 +200,25 @@ Bummers:
...
@@ -200,16 +200,25 @@ Bummers:
+ Output to stdout is captured, but not output to stderr (exception
+ Output to stdout is captured, but not output to stderr (exception
tracebacks are captured via a different means).
tracebacks are captured via a different means).
+ If you continue a line via backslashing in an interactive session, or for
+ If you continue a line via backslashing in an interactive session,
any other reason use a backslash, you need to double the backslash in the
or for any other reason use a backslash, you should use a raw
docstring version. This is simply because you're in a string, and so the
docstring, which will preserve your backslahses exactly as you type
backslash must be escaped for it to survive intact. Like:
them:
>>> if "yes" ==
\
\
>>> def f(x):
... "y" +
\
\
... r'''Backslashes in a raw docstring: m\n'''
... "es": # in the source code you'll see the doubled backslashes
>>> print f.__doc__
... print 'yes'
Backslashes in a raw docstring: m\n
yes
Otherwise, the backslash will be interpreted as part of the string.
E.g., the "\n" above would be interpreted as a newline character.
Alternatively, you can double each backslash in the doctest version
(and not use a raw string):
>>> def f(x):
... '''Backslashes in a raw docstring: m\\n'''
>>> print f.__doc__
Backslashes in a raw docstring: m\n
The starting column doesn't matter:
The starting column doesn't matter:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment