[reportlab-users] Setting Paragraphs as individual elements in a data table

Funke, Matt Matt.funke at vishaypg.com
Wed Apr 11 13:28:02 EDT 2012


Even so, your solution was much more elegant than mine:



headerTableData = []

for i in range(rows):

newList = []

for j in range(cols):

newList.append('')

headerTableData.append(newList)



Thank you for all your help and insight!



Matt Funke

Programmer/Analyst

Vishay Precision Group, Inc.

951 Wendell Blvd

Wendell, NC 27591 USA

Office: 919-374-5553

Mobile: 919-628-9261

Fax: 919-374-5248



From: reportlab-users-bounces at lists2.reportlab.com [mailto:reportlab-users-bounces at lists2.reportlab.com] On Behalf Of Tim Roberts

Sent: Wednesday, April 11, 2012 12:59 PM

To: reportlab-users

Subject: Re: [reportlab-users] Setting Paragraphs as individual elements in a data table



Funke, Matt wrote:





That sounds about right. I made the initial list with these statement:



cols = 2

rows = 3

headerTableData = [[''] * cols] * rows



Yep, that'll do it. As un-Pythonic as it seems, you need to do something like this:



headerTableData = [[''] * cols for j in range(rows)]



That creates a new list every time


>>> y = [['']*cols]*rows



>>> z = [[''] * cols for j in range(rows)]



>>> y


[['', ''], ['', ''], ['', '']]


>>> z


[['', ''], ['', ''], ['', '']]


>>> y[0][1] = '9'



>>> y


[['', '9'], ['', '9'], ['', '9']]


>>> z[0][1] = '9'



>>> z


[['', '9'], ['', ''], ['', '']]


>>>.


--

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/20120411/2cb73924/attachment.html>


More information about the reportlab-users mailing list