Skip to content

Commit 70f777d

Browse files
[3.12] Docs: turn getopt examples into doctests (GH-126377) (#126386)
(cherry picked from commit 0d80777) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent d1b8718 commit 70f777d

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
@@ -92,6 +92,8 @@ exception:
9292

9393
An example using only Unix style options:
9494

95+
.. doctest::
96+
9597
>>> import getopt
9698
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
9799
>>> args
@@ -104,6 +106,8 @@ An example using only Unix style options:
104106

105107
Using long option names is equally easy:
106108

109+
.. doctest::
110+
107111
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
108112
>>> args = s.split()
109113
>>> args
@@ -115,7 +119,9 @@ Using long option names is equally easy:
115119
>>> args
116120
['a1', 'a2']
117121

118-
In a script, typical usage is something like this::
122+
In a script, typical usage is something like this:
123+
124+
.. testcode::
119125

120126
import getopt, sys
121127

@@ -145,7 +151,9 @@ In a script, typical usage is something like this::
145151
main()
146152

147153
Note that an equivalent command line interface could be produced with less code
148-
and more informative help and error messages by using the :mod:`argparse` module::
154+
and more informative help and error messages by using the :mod:`argparse` module:
155+
156+
.. testcode::
149157

150158
import argparse
151159

0 commit comments

Comments
 (0)