Hướng dẫn python print tab align

Resurrecting another topic, but this may come in handy for some.

With a little bit of inspiration from //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 

Chủ Đề