Resurrecting another topic, but this may come in handy for some.
With a little bit of inspiration from https://pyformat.info you can build a method to get a Table of Content [TOC] style printout.
# Define parameters
Location = '10-10-10-10'
Revision = 1
District = 'Tower'
MyDate = 'May 16, 2012'
MyUser = 'LOD'
MyTime = '10:15'
# This is just one way to arrange the data
data = [
['Location: '+Location, 'Revision:'+str(Revision)],
['District: '+District, 'Date: '+MyDate],
['User: '+MyUser,'Time: '+MyTime]
]
# The 'Table of Content' [TOC] style print function
def print_table_line(key,val,space_char,val_loc):
# key: This would be the TOC item equivalent
# val: This would be the TOC page number equivalent
# space_char: This is the spacing character between key and val (often a dot for a TOC), must be >= 5
# val_loc: This is the location in the string where the first character of val would be located
val_loc = max(5,val_loc)
if (val_loc <= len(key)):
# if val_loc is within the space of key, truncate key and
cut_str = '{:.'+str(val_loc-4)+'}'
key = cut_str.format(key)+'...'+space_char
space_str = '{:'+space_char+'>'+str(val_loc-len(key)+len(str(val)))+'}'
print(key+space_str.format(str(val)))
# Examples
for d in data:
print_table_line(d[0],d[1],' ',30)
print('\n')
for d in data:
print_table_line(d[0],d[1],'_',25)
print('\n')
for d in data:
print_table_line(d[0],d[1],' ',20)
The resulting output is as follows:
Location: 10-10-10-10 Revision:1
District: Tower Date: May 16, 2012
User: LOD Time: 10:15
Location: 10-10-10-10____Revision:1
District: Tower__________Date: May 16, 2012
User: LOD________________Time: 10:15
Location: 10-10-... Revision:1
District: Tower Date: May 16, 2012
User: LOD Time: 10:15