doctestprinter.doctest_iter_print

doctestprinter.doctest_iter_print(iterable_to_print: Union[Mapping, Iterable], max_line_width: Optional[int] = 0, indent: Optional[str] = None, edits_item: Optional[Callable[[Any], Any]] = None)

Prints the first level of the iterable or mapping.

Parameters
  • iterable_to_print (Union[Mapping, Iterable]) – A Mapping or Iterable which first level will be iterated and printed.

  • max_line_width (Optional[int]) – Sets the maximum linewidth of the print.

  • indent (Optional[str]) – Additional indentation. The items of mappings will be indented additionally.

  • edits_item (Callable[[Any], Any]) – A callable which takes the 1st level item and returing the state, which should be printed.

Examples

>>> sample_mapping = {"a": "mapping  ", "with": 3, "i": "tems  "}
>>> doctest_iter_print(sample_mapping)
a:
  mapping
with:
  3
i:
  tems
>>> doctest_iter_print(sample_mapping, indent="..")
..a:
....mapping
..with:
....3
..i:
....tems
>>> doctest_iter_print([1, 2, {"a": "mapping  ", "with": 3, "i": "tems  "}])
1
2
{'a': 'mapping  ', 'with': 3, 'i': 'tems  '}
>>> doctest_iter_print(["abc", "abcd", "abcde"], edits_item=lambda x: x[:3])
abc
abc
abc
>>> doctest_iter_print({"edit": 1, "item": 2}, edits_item=lambda x: x**2)
edit:
  1
item:
  4
>>> sample_dict = {"first_level": {"second": "level", "a number": 1.234567}}
>>> doctest_iter_print(sample_dict, edits_item=round_collections)
first_level:
  {'second': 'level', 'a number': 1.235}