[reportlab-users] Problem with a class derived from Table

Robin Becker robin at reportlab.com
Wed Jan 23 05:45:13 EST 2008

shawn a wrote:

> Hello,


> I have a custom table class whose base is Table. When i pass in data

> rows and the table can render itself on ONE page there is no issue.

> But when i pass in a larger data rows list that need to split onto

> other pages i get an exception.


> For the purpose of this email I've stripped the custom table class down to this:


> from reportlab.platypus import Table

> class MyTable(Table):

> def __init__(self,data,**kw):

> Table.__init__(self,data,**kw)


> then in my code


> t = MyTable(data,style=s[0])




> line 860, in _splitRows

> splitByRow=splitByRow)

> TypeError: __init__() takes exactly 2 non-keyword arguments (4 given)



> To recap my custom table class throws the above exception if the list

> data is to large and the table needs to split across pages. It works

> fine if the table can be rendered onto one page

> OR i use the Table class exclusively:(like so)

> t = Table(data,style=s[0])


> thanks,

> -Shawn


I think the error tells it. The signature for myTable() is not the same as for
the original Table() so when the split occurs and the splitByRow method does

R0 = self.__class__( data[:n], self._colWidths, self._argH[:n],
repeatRows=repeatRows, repeatCols=repeatCols,

we're passing three(+self) positional arguments. Two are actually keywords, but
that doesn't matter. It would be more robust to pass these as positional and I
will change the code in the trunk to do that, but without having keyword only
arguments I don't see the right way to do this (ie it's the fact that some
keywords can be passed as positional that causes this problem).
Robin Becker

More information about the reportlab-users mailing list