I would like to output dict data in the form of a table in the console:
dtc={ "test_case1_short":{"test_step11":"pass","test_step12":"pass","test_step_13":{"status":"failed","details":"ca marche po"},
"test_case2_longest_name":{"test_step21":"ne","test_step22":"ne"},
"test_case3_medium_name":{"test_step31":"ne","test_step32":"ne"} }
note: for french speakers 'dtc' is a shortcut for dict_test_collection (!)
To build this table I would like to determine the size of key names in order to dimension my column headers. I can get my key names max length doing this:
max = 0
for i in list(dtc.keys()):
if max < len(i):
max = len(i)
print(max)
but I find this not very straighforward ... is there a way to get this information from dict.keys() or another dict feature ?
Besides, I'd like to set separators like "+-----------------------------+" for section headers and "| |" for section bodies, to have a good looking table. In section bodies, is there a straight and simple way to set the table and columns width (ie. '|' caracter ending up at column 50, whatever the text on the line, like padding the line with spaces until a certain column)
Thank you
Alexandre