Skip to content

Commit 0e5fb0f

Browse files
erlend-aaslandebonnal
authored andcommitted
Docs: turn getopt examples into doctests (python#126377)
1 parent 96d451a commit 0e5fb0f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Doc/library/getopt.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ exception:
9797

9898
An example using only Unix style options:
9999

100+
.. doctest::
101+
100102
>>> import getopt
101103
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
102104
>>> args
@@ -109,6 +111,8 @@ An example using only Unix style options:
109111

110112
Using long option names is equally easy:
111113

114+
.. doctest::
115+
112116
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
113117
>>> args = s.split()
114118
>>> args
@@ -120,7 +124,9 @@ Using long option names is equally easy:
120124
>>> args
121125
['a1', 'a2']
122126

123-
In a script, typical usage is something like this::
127+
In a script, typical usage is something like this:
128+
129+
.. testcode::
124130

125131
import getopt, sys
126132

@@ -150,7 +156,9 @@ In a script, typical usage is something like this::
150156
main()
151157

152158
Note that an equivalent command line interface could be produced with less code
153-
and more informative help and error messages by using the :mod:`argparse` module::
159+
and more informative help and error messages by using the :mod:`argparse` module:
160+
161+
.. testcode::
154162

155163
import argparse
156164

0 commit comments

Comments
 (0)