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

ast.get_docstring

Prev: ast.fix_missing_locations | Up: ast | Next: ast.get_source_segment
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.get_docstring
Tags: #public #python3 #stdlib #ast


Import

import ast
from ast import get_docstring

Signature & Overview

ast.get_docstring(node, clean=True)

Return the docstring for the given node or None if no docstring can be found. If the node provided does not have docstrings a TypeError will be raised.

Usage

import ast

tree = ast.parse('def f():\n    """Hello."""\n    return 1')
assert ast.get_docstring(tree.body[0]) == "Hello."

Gotchas

REPL Inspect

from ast import get_docstring
help(get_docstring)

Linked from

Related notes