Advertisement
Kiri3L

Table_printer

Dec 13th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. def append_to_str(s1, s2, length, filer=' '):
  2.     length -= len(s1)
  3.     s1 += filer*length
  4.     s1 += ' | ' + str(s2)
  5.     return s1
  6.  
  7.  
  8. def resize_list(count):
  9.     l = []
  10.     for i in range(count):
  11.         l.append('')
  12.     return l
  13.  
  14.  
  15. def print_table(table, line_count, colon_count):
  16.     if type(table) is not list:
  17.         print('ERROR 1')
  18.         return
  19.     if len(table) == 0:
  20.         print('ERROR 2')
  21.         return
  22.     print()
  23.     lines = resize_list(line_count)
  24.     length1 = 0
  25.     length2 = 0
  26.     for colon in range(colon_count):
  27.         for line in range(line_count):
  28.             if type(table[line]) is not list:
  29.                 lines[line] = append_to_str(lines[line],'',length1,'-')
  30.             else:
  31.                 lines[line] = append_to_str(lines[line], table[line][colon], length1)
  32.                 length2 = max(len(lines[line]), length2)
  33.         length1 = length2
  34.     for line in lines:
  35.         print(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement