What is the most pythonic way to draw my conclusion. Let me illustrate the behavior I'm trying to achieve. For my project, I create a function that takes different parameters to output the output in columns. An example of a list that it receives.
[('Field', 'Integer', 'Hex'),
('Machine;', 332, '0x14c'),
('NumberOfSections;', 9, '0x9'),
('Time Date Stamp;', 4, '0x4'),
('PointerToSymbolTable;', 126976, '0x1f000')
** The size of the elements may vary (only 3 elements per tuple can now be 4 for another list or any number **
The result should be something like this.
Field Integer Hex
-------------------------------------------------------------------------------
Machine; 332 0x14c
NumberOfSections; 9 0x9
Time Date Stamp; 4 0x4
PointerToSymbolTable; 126976 0x1f000
For work purposes, I created a list that contains only header fields: This is not necessary, but it made it a little easier to try
Header field is ['Field', 'Integer', 'Hex']
" ", .
3 , . :
length_container_header = len(container[0])
.
"print" - .
print("{:21} {:7} {:7}".format(header_field[0], header_field[1], header_field[2]))
, . , "" ,
PointerToSymbolTable . ,
container_lenght_list = []
local_l = 0
for field in range(0, lenght_container_body):
for item in container[1:]:
if len(str(item[field])) > local_l:
local_l = len(str(item[field]))
else:
continue
container_lenght_list.append(str(local_l))
local_l = 0
, [21, 7, 7].
,
formatstring = ""
for line in lst:
formatstring+= "{:" + str(line) +"}"
:
{:21}{:7}{:7}
, ?
format(), . ,
, . - , . , , . , .
,