From c95a953014477aa098349adc44bdfad41a83291b Mon Sep 17 00:00:00 2001 From: Jindra Helcl Date: Mon, 10 Sep 2018 10:31:55 +0200 Subject: [PATCH] better printing of dictionaries and lists in print_examples --- neuralmonkey/learning_utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/neuralmonkey/learning_utils.py b/neuralmonkey/learning_utils.py index 7d4921821..c31cf3dc6 100644 --- a/neuralmonkey/learning_utils.py +++ b/neuralmonkey/learning_utils.py @@ -560,10 +560,12 @@ def print_final_evaluation(name: str, eval_result: Evaluation) -> None: def _data_item_to_str(item: Any) -> str: if isinstance(item, list): - return " ".join([str(i) for i in item]) + return " ".join([_data_item_to_str(i) for i in item]) - if isinstance(item, str): - return item + if isinstance(item, dict): + return "{\n " + "\n ".join( + ["{}: {}".format(_data_item_to_str(key), _data_item_to_str(val)) + for key, val in item.items()]) + "\n }" if isinstance(item, np.ndarray) and len(item.shape) > 1: return "[numpy tensor, shape {}]".format(item.shape)