inspect_recursive package

This package provides functionality for inspecting Python object structures.

Functions

what(obj, max_depth=4, obj_name=””, thresh_iter_list=1, thresh_iter_dict=3, thresh_repr_obj=100)

Inspect the structure of an object and print it.

Examples

Usage examples:
>>> import inspect_recursive as ipr
>>> simple_dict = {"a": 1, "b": 2, "c": 3}
>>> ipr.what(simple_dict)
inspector<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-  : <class 'dict'>
  - a : <class 'int'>
  - b : <class 'int'>
  - c : <class 'int'>
>>> nested_dict = {"a": {"x": 1, "y": 2}, "b": {"z": 3}}
>>> ipr.what(nested_dict)
inspector<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-  : <class 'dict'>
  - a : <class 'dict'>
    - x : <class 'int'>
    - y : <class 'int'>
  - b : <class 'dict'>
    - z : <class 'int'>
>>> list_of_strings = ["apple", "banana", "cherry"]
>>> ipr.what(list_of_strings)
inspector<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-  : <class 'list'>
  >len=3 content-type=<class 'str'> vals=['apple', 'banana', 'cherry']

Submodules

This module provides functions for inspecting the structure of Python objects.

Functions

repr_truncated(obj, length)

Return a truncated string representation of the object.

inspect_object_structure_as_tree(obj, depth=0, obj_name=””, **kwargs)

Recursively inspect the structure of an object and print it as a tree.

inspect_object_structure(obj, max_depth=4, obj_name=””, thresh_iter_list=1, thresh_iter_dict=3, thresh_repr_obj=100)

Inspect the structure of an object and print it.

inspect_recursive.inspect_object_structure.inspect_object_structure(obj, max_depth=4, obj_name='', thresh_iter_list=1, thresh_iter_dict=3, thresh_repr_obj=100)

Inspect the structure of an object and print it.

Parameters:
  • obj (object) – The object to inspect.

  • max_depth (int, optional) – The maximum depth to traverse while inspecting. (default is 4)

  • obj_name (str, optional) – The name of the object. (default is “”)

  • thresh_iter_list (int, optional) – Threshold for iteration on lists. (default is 1)

  • thresh_iter_dict (int, optional) – Threshold for iteration on dictionaries. (default is 3)

  • thresh_repr_obj (int, optional) – Threshold for object representation length. (default is 100)

Examples

>>> data = {'a': 1, 'b': {'c': [1, 2, 3]}}
>>> inspect_object_structure(data)
inspector<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-  : <class 'dict'>
  - a : <class 'int'>
  - b : <class 'dict'>
    - c : <class 'list'>
      >len=3 content-type=<class 'int'> vals=[1, 2, 3]
>>> inspect_object_structure([1, 2, 3, 4, 5], obj_name="example_list")
inspector<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- example_list : <class 'list'>
  >len=5 content-type=<class 'int'> vals=[1, 2, 3, 4, 5]