问题
This is my first StackOverflow post so I would like to apologize if I have made any markup mistakes or anything similar.
This is the current project I am working on: I am developing a Django web application that's responsible for generating audit reports based on dynamic input by the user. The user will have the option to refer a variation of files.
The current issue I am facing is the following:
I would like to generate a bulletlist of static elements given in a list. This is the code I have so far.
def generateList(list_of_bullets):
styles = getSampleStyleSheet()
t1 = ListFlowable([
for element in list_of_bullets:
ListItem(Paragraph(element, styles['Normal']), bulletColor=CMYKColor(0.81,0.45,0.53,0.23), value='circle')
)], bulletType='bullet', start='circle')
story.append(t1)
PyCharm reports a Expression expected on ListFlowable([ <-
the code below works just fine
def get_bullet_list():
styles = getSampleStyleSheet()
t1 = ListFlowable([ListItem(Paragraph("Sample Text", styles['Normal']), bulletColor=CMYKColor(0.81, 0.45, 0.53, 0.23), value='circle')], bulletType='bullet', start='circle')
So my question is: Is there any way I can dynamically append ListItems to a ListFlowable?
回答1:
I figured out how to do this dynamically thanks to a kind user on #python @ irc.freenode.org.
The following code is tested and works.
def makeBulletList(list):
styles=getSampleStyleSheet()
style=styles['Normal']
table=ListFlowable([ListItem(Paragraph(x, style), leftIndent=35, bulletColor='black', value='circle') for x in list], bulletType='bullet')
return table
来源:https://stackoverflow.com/questions/33364383/reportlab-listflowable-generate-listitem-from-given-list-of-strings