How to add items iteratively to the body?
jbramle2 opened this issue · 4 comments
Is there a way to add a list of lists to the body section? I can see that you can add them as list variables themselves. However, I would like to have the ascii table dynamically update from time to time with a different number of items. Is this currently possible? I have attempted to add lists of lists and it takes it as a single list.

In Python, you can add items to a list with the + operator.
For example:
body = test_list + [ ["3", "jamie", "1000.23"], ["4", "Mack", "500"] ]Full example:
test_list = [ ["1", "Mike", "7000.23"], ["2", "Daniel", "2300.23"] ]
output = table2ascii(
header=["Rank", "Player", "Rating"],
body=test_list + [
["3", "jamie", "1000.23"],
["4", "Mack", "500"],
],
)Let me know if that helps.
Hi, thanks for the help. However, I don't think that solves the issue. It is reading "["1", "Mike", "7000.23"]" as column 1 and ["2", "Daniel", "2300.23"] as column 2.
It attempts to place the entirety of test_list[0] into the "Rank" column and then test_list[1] into the "Player" column. I have been unable to use a list of lists within the body section without explicitly specifying the index, as in my 2nd example screenshot. For the sake of the top level length of the list being dynamic, I believe I would need to define it outside of the body content. I just can't get it to accept a list of lists. Here is a more simple example of the issue.

Oh. I figured it out! I just removed the brackets from the body definition.
test_list = [["1", "Mike", "7000.23"], ["2", "Daniel", "2300.23"], ["3", "James", "1100.23"]]
output = table2ascii(
header=["Rank", "Player", "Rating"],
body=test_list,
column_widths=[6, 10, 10],
alignments=[Alignment.LEFT, Alignment.LEFT, Alignment.DECIMAL],
)
Thanks for your help!
