doctestprinter.EditingItem¶
-
class
doctestprinter.
EditingItem
(editor: Callable, *editor_args, **editor_kwargs)¶ EditingItem is a wrapper class for the edit_item argument of
doctest_iter_print()
.- Parameters
editor (Callable[[Any], Any]) – A callable which first argument is the item to be edited, before printing.
editor_args – Arguments for the editor.
editor_kwargs – Keyword arguments for the editor.
Examples
prepare_pandas accepts 4 arguments. edits_item of
doctest_iter_print()
takes a Callable and passes each item within the iteration as the first argument to the editor. Therefor edits_pandas allows to predefine the arguments for any Callable, which provides additional functionality.>>> from doctestprinter import ( ... EditingItem, doctest_iter_print, prepare_pandas ... ) >>> from pandas import DataFrame >>> frame_1 = DataFrame.from_records({"Alpha": 1, "Beta": 2}, index=[1.234]) >>> frame_2 = DataFrame({"Gamma":3, "Delta": 4}, index=[2.345]) >>> edits_pandas = EditingItem(prepare_pandas, formats="{:>.1f}#{:>8}") >>> doctest_iter_print([frame_1, frame_2], edits_item=edits_pandas) Alpha Beta 1.2 1 2 Gamma Delta 2.3 3 4
-
__init__
(editor: Callable, *editor_args, **editor_kwargs)¶ EditingItem is a wrapper class for the edit_item argument of
doctest_iter_print()
.- Parameters
editor (Callable[[Any], Any]) – A callable which first argument is the item to be edited, before printing.
editor_args – Arguments for the editor.
editor_kwargs – Keyword arguments for the editor.
Examples
prepare_pandas accepts 4 arguments. edits_item of
doctest_iter_print()
takes a Callable and passes each item within the iteration as the first argument to the editor. Therefor edits_pandas allows to predefine the arguments for any Callable, which provides additional functionality.>>> from doctestprinter import ( ... EditingItem, doctest_iter_print, prepare_pandas ... ) >>> from pandas import DataFrame >>> frame_1 = DataFrame.from_records({"Alpha": 1, "Beta": 2}, index=[1.234]) >>> frame_2 = DataFrame({"Gamma":3, "Delta": 4}, index=[2.345]) >>> edits_pandas = EditingItem(prepare_pandas, formats="{:>.1f}#{:>8}") >>> doctest_iter_print([frame_1, frame_2], edits_item=edits_pandas) Alpha Beta 1.2 1 2 Gamma Delta 2.3 3 4
Methods
__init__
(editor, *editor_args, **editor_kwargs)EditingItem is a wrapper class for the edit_item argument of
doctest_iter_print()
.