diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-11-04 08:27:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-04 08:27:25 (GMT) |
commit | 0d80777981f95bbc79b146fc78b2189c82521ab9 (patch) | |
tree | b4deffaaf6b8e9b5af7c3fc4b2e733473de391c2 /Doc | |
parent | 081706f873b7d1a10b27016a9ed350b20c719709 (diff) | |
download | cpython-0d80777981f95bbc79b146fc78b2189c82521ab9.zip cpython-0d80777981f95bbc79b146fc78b2189c82521ab9.tar.gz cpython-0d80777981f95bbc79b146fc78b2189c82521ab9.tar.bz2 |
Docs: turn getopt examples into doctests (#126377)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/getopt.rst | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Doc/library/getopt.rst b/Doc/library/getopt.rst index d43d325..3ab44b9 100644 --- a/Doc/library/getopt.rst +++ b/Doc/library/getopt.rst @@ -97,6 +97,8 @@ exception: An example using only Unix style options: +.. doctest:: + >>> import getopt >>> args = '-a -b -cfoo -d bar a1 a2'.split() >>> args @@ -109,6 +111,8 @@ An example using only Unix style options: Using long option names is equally easy: +.. doctest:: + >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2' >>> args = s.split() >>> args @@ -120,7 +124,9 @@ Using long option names is equally easy: >>> args ['a1', 'a2'] -In a script, typical usage is something like this:: +In a script, typical usage is something like this: + +.. testcode:: import getopt, sys @@ -150,7 +156,9 @@ In a script, typical usage is something like this:: main() Note that an equivalent command line interface could be produced with less code -and more informative help and error messages by using the :mod:`argparse` module:: +and more informative help and error messages by using the :mod:`argparse` module: + +.. testcode:: import argparse |