Skip to content

pdir

prettydir

prettydir(obj: RuntimeValue, include_dunders: bool = False, color: bool = True, sep: bool = False, indent: int = 2) -> None

Print the attributes and methods of an object in a pretty format.

Parameters:

Name Type Description Default
obj object

The object to be inspected.

required
include_dunders bool

Whether to include dunder methods.

False
color bool

Whether to colorize the output.

True
sep bool

Whether to print a separator before and after the output.

False
indent int

Indent width.

2
Source code in objinspect/prettydir.py
def prettydir(
    obj: RuntimeValue,
    include_dunders: bool = False,
    color: bool = True,
    sep: bool = False,
    indent: int = 2,
) -> None:
    """
    Print the attributes and methods of an object in a pretty format.

    Args:
        obj (object): The object to be inspected.
        include_dunders (bool, optional): Whether to include dunder methods.
        color (bool, optional): Whether to colorize the output.
        sep (bool, optional): Whether to print a separator before and after the output.
        indent (int, optional): Indent width.
    """
    if sep:
        br()

    data = _collect_data(obj)
    _print_dunders(data["dunders"], include_dunders=include_dunders, color=color, indent=indent)
    _print_variables(data["vars"], color=color, indent=indent)
    _print_function_like_section(
        "Methods",
        _collect_methods_of_type(data["methods"], Method),
        color=color,
        indent=indent,
    )
    _print_function_like_section(
        "Functions",
        _collect_methods_of_type(data["methods"], Function),
        color=color,
        indent=indent,
    )

    if sep:
        br()