Question

At the moment I have a list of objects as below. And I can print them out by iterating over them no problem. But I don't understand how I can print these out in a table.

people = [("John","Smith"), ("Jane","Doe"), ("Jane","Smith")]

for x in people:

    person = x

    lineText = (person.getFirstName() + " " + person.getLastName())

    p = Paragraph(lineText, helveticaUltraLight)
    Story.append(p)

I had a look at this example. Specifically the enumeration of the users in the example. However this always falls over.

Was it helpful?

Solution

I figured it out:

people = [("John","Smith"), ("Jane","Doe"), ("Jane","Smith")]
table_data = []
for i, person in enumerate(people):
    # Add a row to the table
    table_data.append([person[0], person[1]])
# Create the table
issue_table = Table(table_data, colWidths=[doc.width/3.0]*3)

Story.append(issue_table)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top