Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: turn getopt examples into doctests #126377

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Doc/library/getopt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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::
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

import getopt, sys

Expand Down Expand Up @@ -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

Expand Down
Loading