On this page
  1. doctest.script_from_examples
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

doctest.script_from_examples

Prev: doctest.run_docstring_examples | Up: doctest | Next: doctest.set_unittest_reportflags
Rel: doctest.debug, doctest.debug_src, doctest.DebugRunner, doctest.DocFileSuite
Ref: docs.python.org — doctest.script_from_examples
Tags: #public #python3 #stdlib #doctest


Import

import doctest
from doctest import script_from_examples

Signature & Overview

doctest.script_from_examples(s)

Extract script from text with examples.

Usage

import doctest

script = doctest.script_from_examples(">>> x = 2\n>>> x * 3\n6\n")
assert "x = 2" in script and "# Expected:" in script

Gotchas

REPL Inspect

from doctest import script_from_examples
help(script_from_examples)

Linked from

Related notes