目前我有一个对象列表,如下所示。我可以通过迭代打印它们没问题。但是我不明白我怎么能把它们打印出来。
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)
我查看了this示例。特别是示例中的用户枚举。然而,这总是会失败。
答案 0 :(得分:0)
我明白了:
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)