[reportlab-users] looping through text error.
Tim Roberts
timr at probo.com
Fri Apr 13 12:58:05 EDT 2012
Siddique, Halil wrote:
>
> Hi all,
>
> I’ve only just looked at reportlab for the last few days so please
> bear with me.
>
> I have a script that was already in use and tried to modify it, what
> the code should do is loop through all the records, and append them to
> a list, butIcannot get it to work.
>
> ...
>
> When the code goes into thesecondwhileloop (mySelectedGroups), it
> loops through and adds the data to the variable data, but when it
> exits the loop and goes into story.append(data),an error occurs
>
> AttributeError:'list'objecthasnoattribute'getKeepWithNext'
>
> So my question is how to a list the values that are looped into my pdf?
This happens because "data" is a Python list, not a Platypus flowable.
The "story" variable that you pass to doc.build must be a list of
flowables. Your first loop does that, but when you add a plain Python
list, it doesn't work. Remember, when you call list.append, that adds
it parameter as a single item. So:
x = [1,2,3]
y = [4,5,6]
x.append( y )
x now has [1,2,3,[4,5,6]] That is, x contains 4 items, the last of
which happens to be a list.
I don't quite understand why you accumulate the second loop into a
separate list (data) instead of just appending it straight to story, but
that's a separate matter. You can add certainly add the CONTENTS of a
list onto another list, in two ways:
story += data
or
story.extend( data )
So:
x = [1,2,3]
y = [4,5,6]
x += y
x now contains [1,2,3,4,5,6].
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20120413/05de47a0/attachment.html>
More information about the reportlab-users
mailing list