Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
92816de1
Kaydet (Commit)
92816de1
authored
May 31, 2004
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #932930: suggest the use of rawstrings for backslashes.
üst
2a6ba909
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
21 deletions
+41
-21
libdoctest.tex
Doc/lib/libdoctest.tex
+20
-9
doctest.py
Lib/doctest.py
+21
-12
No files found.
Doc/lib/libdoctest.tex
Dosyayı görüntüle @
92816de1
...
...
@@ -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
the
m
:
\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:
...
...
Lib/doctest.py
Dosyayı görüntüle @
92816de1
...
...
@@ -4,7 +4,7 @@
# 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
...
...
@@ -200,17 +200,26 @@ Bummers:
+ Output to stdout is captured, but not output to stderr (exception
tracebacks are captured via a different means).
+ 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:
>>> if "yes" ==
\\
... "y" +
\\
... "es": # in the source code you'll see the doubled backslashes
... print 'yes'
yes
+ 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:
>>> def f(x):
... r'''Backslashes in a raw docstring: m\n'''
>>> print f.__doc__
Backslashes in a raw docstring: m\n
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:
>>> assert "Easy!"
...
...
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