termtables
termtables copied to clipboard
index out of range error

Always copy-and-paste your code, never screenshot it. Copy-and-pasting makes it searchable.
Also, I need a minimal example that reproduces the error.
I was able to replicate the error when a row contains: \n
Try with: "something blabla \n more etc"
sorry for using screenshot. the error occurs exactly like what @maborak asserts
Yes, screenshots are terrible. Not to pile on, but if you are going to bother reporting a problem, make it something actionable.
I think the problem is in this method:
def _hjoin_multiline(join_char, strings):
"""Horizontal join of multiline strings"""
cstrings = [string.split("\n") for string in strings]
max_num_lines = max(len(item) for item in cstrings)
pp = []
for k in range(max_num_lines):
p = [cstring[k] for cstring in cstrings]
pp.append(join_char + join_char.join(p) + join_char)
return "\n".join([p.rstrip() for p in pp])
max_num_lines is the maximum number of lines in at least one cell for all cells in a row. However, if a cell has fewer than that, then k index will be out of range of cstring
Reproduce with:
header = ["A", "B\nB","C"]
data = [["a", "b", "c"]]
tt.print(
data,
header=header,
)