{
  "$type": "site.standard.document",
  "canonicalUrl": "https://rednafi.com/python/inspect-docstring-with-pydoc/",
  "description": "View Python docstrings from the command line with pydoc or serve them as HTML documentation for modules, classes, and functions.",
  "path": "/python/inspect-docstring-with-pydoc/",
  "publishedAt": "2022-01-22T00:00:00.000Z",
  "site": "at://did:plc:fgtm2c26vfcj74rfmeggbyqj/site.standard.publication/3mnl6f7ob462z",
  "tags": [
    "Python",
    "CLI"
  ],
  "textContent": "How come I didn't know about the python -m pydoc command before today!\n\n> It lets you inspect the docstrings of any modules, classes, functions, or methods in\n> Python.\n\nI'm running the commands from a Python 3.10 virtual environment but it'll work on any Python\nversion. Let's print out the docstrings of the functools.lru_cache function. Run:\n\nThis will print the following on the console:\n\nWorks for third party tools as well:\n\nAlso, works for any custom Python structure that is accessible from the current Python path.\nLet's define a function with docstrings and put that in a module called src.py:\n\nYou can inspect the entire src.py module or the greetings function specifically as\nfollows:\n\nTo inspect the module, run:\n\nTo inspect the greetings function only, run:\n\nIt'll return:\n\nInstead of inspecting the docstrings one by one, you can also pull up all of them in the\ncurrent Python path and serve them as HTML pages. To do so, run:\n\nThis will render the docstrings as HTML web pages and automatically open the index page with\nyour default browser. From there you can use the built-in search to find and read your ones\nyou need.\n\nFurther reading\n\n- [Tweet by Brandon Rhodes]\n\n\n\n\n[tweet by brandon rhodes]:\n    https://twitter.com/brandon_rhodes/status/1354416534098214914",
  "title": "Inspect docstrings with Pydoc"
}