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
225c8f44
Commit
225c8f44
authored
Sep 26, 2004
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give a saner example for script_from_examples(); also mention an intended
but not entirely obvious use case.
parent
a1851620
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
Doc/lib/libdoctest.tex
Doc/lib/libdoctest.tex
+25
-11
No files found.
Doc/lib/libdoctest.tex
View file @
225c8f44
...
...
@@ -1655,22 +1655,36 @@ the synthesized code under the debugger:
is converted to a Python script, where doctest examples in
\var
{
s
}
are converted to regular code, and everything else is converted to
Python comments. The generated script is returned as a string.
For example,
given file
\file
{
a.py
}
as above,
For example,
\begin{verbatim}
>>> print doctest.script
_
from
_
examples(open("a.py").read())
# """
def f(x):
g(x*2)
def g(x):
print x+3
import pdb; pdb.set
_
trace()
f(3)
import doctest
print doctest.script
_
from
_
examples(r"""
Set x and y to 1 and 2.
>>> x, y = 1, 2
Print their sum:
>>> print x+y
3
""")
\end{verbatim}
displays:
\begin{verbatim}
# Set x and y to 1 and 2.
x, y = 1, 2
#
# Print their sum:
print x+y
# Expected:
## 9
## """
## 3
\end{verbatim}
This function is used internally by other functions (see below), but
can also be useful when you want to transform an interactive Python
session into a Python script.
\versionadded
{
2.4
}
\end{funcdesc}
...
...
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