Display text documentation, given an object or a path to an object.
(thing, title='Python Library Documentation: %s', forceload=0,
output=None, is_cli=False)
| 1737 | return title % desc + '\n\n' + renderer.document(object, name) |
| 1738 | |
| 1739 | def doc(thing, title='Python Library Documentation: %s', forceload=0, |
| 1740 | output=None, is_cli=False): |
| 1741 | """Display text documentation, given an object or a path to an object.""" |
| 1742 | if output is None: |
| 1743 | try: |
| 1744 | if isinstance(thing, str): |
| 1745 | what = thing |
| 1746 | else: |
| 1747 | what = getattr(thing, '__qualname__', None) |
| 1748 | if not isinstance(what, str): |
| 1749 | what = getattr(thing, '__name__', None) |
| 1750 | if not isinstance(what, str): |
| 1751 | what = type(thing).__name__ + ' object' |
| 1752 | pager(render_doc(thing, title, forceload), f'Help on {what!s}') |
| 1753 | except ImportError as exc: |
| 1754 | if is_cli: |
| 1755 | raise |
| 1756 | print(exc) |
| 1757 | else: |
| 1758 | try: |
| 1759 | s = render_doc(thing, title, forceload, plaintext) |
| 1760 | except ImportError as exc: |
| 1761 | s = str(exc) |
| 1762 | output.write(s) |
| 1763 | |
| 1764 | def writedoc(thing, forceload=0): |
| 1765 | """Write HTML documentation to a file in the current directory.""" |
no test coverage detected