I’m trying to use ElementTree to create an html element with a class, like so:
nextLink = ElementTree.SubElement(root_element, "a", class="bah",href="www.bah.com")
However, I get the following error message:
SyntaxError: invalid syntax
I think it’s because ‘class’ is a reserved keyword in Python. If I change the spelling or case of class it works, but that doesn’t fix my problem as I need the output to be ‘class’.
Is there a workaround?
Thanks,
pass in a dict of ‘attrib’: ‘value’ pairs