Search code examples
pythonhtmlhtml-generation

How to set element class attribute in the XIST python module


I'm just getting a handle on this xist html generating code and I have the overall structure working out fine for the document but am ready to begin labeling all the various elements with their classes to later be styled by CSS. I'm struggling to figure out how to tag an element with a class attribute. If I do something like...

with html.td() :
    with xsc.addattr("class" ) :
        +xsc.Text("ColumnHeader")
    +xsc.Text( "Image Name" )

I'll get the following error

Traceback ...
ll.xist.xsc.IllegalAttrError: no local attribute with Python name 'class' in <attrs class ll.xist.ns.html:td.Attrs with 32 attrs at 0x2a0bed8>

Solution

  • Really subtle, you have to use class_ to get it done.

    with xsc.addattr("class_" ) :
    

    or more compactly

    with html.td( class_="ColumnHeader" ) :