Hướng dẫn python tab formatted printing - in định dạng thẻ python

Phục sinh một chủ đề khác, nhưng điều này có thể có ích cho một số người.

Với một chút cảm hứng từ //pyformat.info, bạn có thể xây dựng một phương thức để có được một bảng nội dung [TOC] in phong cách.

# 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ủ Đề